50 lines
1.0 KiB
TypeScript
50 lines
1.0 KiB
TypeScript
import { z } from "zod/v4";
|
|
|
|
export const register = z.object({
|
|
type: z.literal("register"),
|
|
username: z.string(),
|
|
password: z.string()
|
|
});
|
|
|
|
export type Register = z.infer<typeof register>;
|
|
|
|
export const offer = z.object({
|
|
type: z.literal("offer"),
|
|
id: z.uuid({ version: "v4" }),
|
|
offer: z.object({
|
|
type: z.literal("offer"),
|
|
sdp: z.string()
|
|
})
|
|
});
|
|
|
|
export type Offer = z.infer<typeof offer>;
|
|
|
|
export const answer = z.object({
|
|
type: z.literal("answer"),
|
|
id: z.uuid({ version: "v4" }),
|
|
answer: z.object({
|
|
type: z.literal("answer"),
|
|
sdp: z.string()
|
|
})
|
|
});
|
|
|
|
export type Answer = z.infer<typeof answer>;
|
|
|
|
export const candidate = z.object({
|
|
type: z.literal("candidate"),
|
|
id: z.uuid({ version: "v4" }),
|
|
candidate: z.looseObject({
|
|
candidate: z.string()
|
|
})
|
|
});
|
|
|
|
export type Candidate = z.infer<typeof candidate>;
|
|
|
|
export const schemas = z.union([
|
|
register,
|
|
offer,
|
|
answer,
|
|
candidate
|
|
]);
|
|
|
|
export type Message = z.infer<typeof schemas>; |