@4players/odin-common 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mod.d.ts +26 -4431
- package/package.json +1 -1
- package/plugin/api.d.ts +159 -0
- package/rpc/commands.d.ts +253 -0
- package/rpc/notifications.d.ts +1626 -0
- package/schema/channels.d.ts +11 -0
- package/schema/media.d.ts +122 -0
- package/schema/message.d.ts +12 -0
- package/schema/peer.d.ts +226 -0
- package/schema/room.d.ts +1673 -0
- package/schema/serialization.d.ts +12 -0
- package/schema/token.d.ts +58 -0
- package/schema/webrtc.d.ts +42 -0
- package/utility/base64.d.ts +3 -0
- package/utility/bytearray.d.ts +4 -0
- package/utility/codec.d.ts +15 -0
- package/utility/environment.d.ts +6 -0
- package/utility/iterable.d.ts +1 -0
- package/utility/json.d.ts +2 -0
- package/utility/log.d.ts +79 -0
- package/utility/result.d.ts +18 -0
- package/utility/selector.d.ts +7 -0
- package/utility/sleep.d.ts +4 -0
- package/utility/strand.d.ts +8 -0
- package/utility/url.d.ts +3 -0
- package/utility/uuid.d.ts +2 -0
- package/utility/validation.d.ts +10 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const ByteArraySchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
3
|
+
export type ByteArray = z.infer<typeof ByteArraySchema>;
|
|
4
|
+
declare const LiteralSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
5
|
+
type Literal = z.infer<typeof LiteralSchema>;
|
|
6
|
+
export type Json = Literal | {
|
|
7
|
+
[key: string]: Json;
|
|
8
|
+
} | Json[];
|
|
9
|
+
export declare const JsonSchema: z.ZodType<Json>;
|
|
10
|
+
export declare const MessagePackRpcSchema: z.ZodUnion<[z.ZodTuple<[z.ZodLiteral<0>, z.ZodNumber, z.ZodString, z.ZodUnknown], null>, z.ZodTuple<[z.ZodLiteral<1>, z.ZodNumber, z.ZodNullable<z.ZodString>, z.ZodUnknown], null>, z.ZodTuple<[z.ZodLiteral<2>, z.ZodString, z.ZodUnknown], null>]>;
|
|
11
|
+
export type MessagePackRpc = z.infer<typeof MessagePackRpcSchema>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const TokenAudienceSchema: z.ZodEnum<["sfu", "gateway"]>;
|
|
3
|
+
export declare const TokenSubjectSchema: z.ZodEnum<["connect", "roomclose", "roomupdate", "roombanclient", "roomsendmessage"]>;
|
|
4
|
+
export declare const TokenClaimsSchema: z.ZodObject<{
|
|
5
|
+
uid: z.ZodString;
|
|
6
|
+
cid: z.ZodOptional<z.ZodString>;
|
|
7
|
+
rid: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
|
|
8
|
+
nsp: z.ZodOptional<z.ZodString>;
|
|
9
|
+
adr: z.ZodOptional<z.ZodString>;
|
|
10
|
+
aud: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["sfu", "gateway"]>, z.ZodArray<z.ZodEnum<["sfu", "gateway"]>, "many">]>>;
|
|
11
|
+
sub: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["connect", "roomclose", "roomupdate", "roombanclient", "roomsendmessage"]>, z.ZodArray<z.ZodEnum<["connect", "roomclose", "roomupdate", "roombanclient", "roomsendmessage"]>, "many">]>>;
|
|
12
|
+
exp: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
nbf: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
ups: z.ZodOptional<z.ZodString>;
|
|
15
|
+
tgs: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
16
|
+
tsp: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
internal: z.ZodOptional<z.ZodObject<{
|
|
18
|
+
server: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
server?: string;
|
|
21
|
+
}, {
|
|
22
|
+
server?: string;
|
|
23
|
+
}>>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
sub?: "connect" | "roomclose" | "roomupdate" | "roombanclient" | "roomsendmessage" | ("connect" | "roomclose" | "roomupdate" | "roombanclient" | "roomsendmessage")[];
|
|
26
|
+
internal?: {
|
|
27
|
+
server?: string;
|
|
28
|
+
};
|
|
29
|
+
uid?: string;
|
|
30
|
+
cid?: string;
|
|
31
|
+
rid?: string | string[];
|
|
32
|
+
nsp?: string;
|
|
33
|
+
adr?: string;
|
|
34
|
+
aud?: "sfu" | "gateway" | ("sfu" | "gateway")[];
|
|
35
|
+
exp?: number;
|
|
36
|
+
nbf?: number;
|
|
37
|
+
ups?: string;
|
|
38
|
+
tgs?: string | string[];
|
|
39
|
+
tsp?: number;
|
|
40
|
+
}, {
|
|
41
|
+
sub?: "connect" | "roomclose" | "roomupdate" | "roombanclient" | "roomsendmessage" | ("connect" | "roomclose" | "roomupdate" | "roombanclient" | "roomsendmessage")[];
|
|
42
|
+
internal?: {
|
|
43
|
+
server?: string;
|
|
44
|
+
};
|
|
45
|
+
uid?: string;
|
|
46
|
+
cid?: string;
|
|
47
|
+
rid?: string | string[];
|
|
48
|
+
nsp?: string;
|
|
49
|
+
adr?: string;
|
|
50
|
+
aud?: "sfu" | "gateway" | ("sfu" | "gateway")[];
|
|
51
|
+
exp?: number;
|
|
52
|
+
nbf?: number;
|
|
53
|
+
ups?: string;
|
|
54
|
+
tgs?: string | string[];
|
|
55
|
+
tsp?: number;
|
|
56
|
+
}>;
|
|
57
|
+
export type TokenClaims = z.infer<typeof TokenClaimsSchema>;
|
|
58
|
+
export declare function oneOrMany<T extends z.ZodTypeAny>(type: T): z.ZodUnion<[T, z.ZodArray<T, "many">]>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const WebRtcUpdateSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
|
|
3
|
+
kind: z.ZodLiteral<"Sdp">;
|
|
4
|
+
type: z.ZodEnum<["Answer", "Offer"]>;
|
|
5
|
+
sdp: z.ZodString;
|
|
6
|
+
media_map: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodString], null>, "many">;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
type?: "Answer" | "Offer";
|
|
9
|
+
kind?: "Sdp";
|
|
10
|
+
sdp?: string;
|
|
11
|
+
media_map?: [number, string, ...unknown[]][];
|
|
12
|
+
}, {
|
|
13
|
+
type?: "Answer" | "Offer";
|
|
14
|
+
kind?: "Sdp";
|
|
15
|
+
sdp?: string;
|
|
16
|
+
media_map?: [number, string, ...unknown[]][];
|
|
17
|
+
}>, z.ZodObject<{
|
|
18
|
+
kind: z.ZodLiteral<"Trickle">;
|
|
19
|
+
candidate: z.ZodString;
|
|
20
|
+
spd_mid: z.ZodOptional<z.ZodString>;
|
|
21
|
+
spd_mline_index: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
username_fragment: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
candidate?: string;
|
|
25
|
+
kind?: "Trickle";
|
|
26
|
+
spd_mid?: string;
|
|
27
|
+
spd_mline_index?: number;
|
|
28
|
+
username_fragment?: string;
|
|
29
|
+
}, {
|
|
30
|
+
candidate?: string;
|
|
31
|
+
kind?: "Trickle";
|
|
32
|
+
spd_mid?: string;
|
|
33
|
+
spd_mline_index?: number;
|
|
34
|
+
username_fragment?: string;
|
|
35
|
+
}>, z.ZodObject<{
|
|
36
|
+
kind: z.ZodLiteral<"TrickleFinished">;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
kind?: "TrickleFinished";
|
|
39
|
+
}, {
|
|
40
|
+
kind?: "TrickleFinished";
|
|
41
|
+
}>]>;
|
|
42
|
+
export type WebRtcUpdate = z.infer<typeof WebRtcUpdateSchema>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Result } from "./result.ts";
|
|
2
|
+
declare const validCodecs: readonly ["VP8", "VP9", "AV1", "H264"];
|
|
3
|
+
export type Codec = (typeof validCodecs)[number];
|
|
4
|
+
export declare class VideoCodec {
|
|
5
|
+
readonly codec: Codec;
|
|
6
|
+
readonly channels = 0;
|
|
7
|
+
readonly clockRate = 90000;
|
|
8
|
+
constructor(codec: Codec);
|
|
9
|
+
isValid(): boolean;
|
|
10
|
+
isSupported(): RTCRtpCodec | null;
|
|
11
|
+
getPayloadType(): Result<number>;
|
|
12
|
+
getMimeType(): Result<string>;
|
|
13
|
+
getSdpFmtpLine(): Result<string>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function isAudioCapable(): boolean;
|
|
2
|
+
export declare function isSharedArrayBufferCapable(): boolean;
|
|
3
|
+
export declare function isBlinkBrowser(): boolean;
|
|
4
|
+
export declare function isElectronBrowser(): boolean;
|
|
5
|
+
export declare function isFirefoxBrowser(): boolean;
|
|
6
|
+
export declare function isSafariBrowser(): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function find<T>(entries: Iterable<T>, predicate: (entry: T) => boolean): T | undefined;
|
package/utility/log.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type Result } from "./result.ts";
|
|
2
|
+
export declare enum LogVerbosity {
|
|
3
|
+
NONE = 0,
|
|
4
|
+
ERROR = 1,
|
|
5
|
+
WARN = 2,
|
|
6
|
+
INFO = 3,
|
|
7
|
+
DEBUG = 4
|
|
8
|
+
}
|
|
9
|
+
export type LogLevel = (typeof LogVerbosity)[LogLevelName];
|
|
10
|
+
export type LogLevelName = Exclude<keyof typeof LogVerbosity, number>;
|
|
11
|
+
export declare const LogLevels: LogLevel[];
|
|
12
|
+
export declare const LogLevelNames: LogLevelName[];
|
|
13
|
+
export declare const LogSymbols: {
|
|
14
|
+
[Level in LogLevel]: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const LogFunctions: {
|
|
17
|
+
[Level in LogLevel]: (...data: unknown[]) => void;
|
|
18
|
+
};
|
|
19
|
+
export declare function getLevelByName(name: LogLevelName): Result<LogLevel>;
|
|
20
|
+
export declare function getLevelName(level: LogLevel): Result<LogLevelName>;
|
|
21
|
+
export interface LoggerOptions {
|
|
22
|
+
handlers?: LogHandler[];
|
|
23
|
+
}
|
|
24
|
+
export declare function getLogger(name?: string): Logger;
|
|
25
|
+
export declare function error<T>(msg: () => T, ...args: unknown[]): T | undefined;
|
|
26
|
+
export declare function error<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
|
|
27
|
+
export declare function warn<T>(msg: () => T, ...args: unknown[]): T | undefined;
|
|
28
|
+
export declare function warn<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
|
|
29
|
+
export declare function info<T>(msg: () => T, ...args: unknown[]): T | undefined;
|
|
30
|
+
export declare function info<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
|
|
31
|
+
export declare function debug<T>(msg: () => T, ...args: unknown[]): T | undefined;
|
|
32
|
+
export declare function debug<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
|
|
33
|
+
export declare class Logger {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
private _Level;
|
|
36
|
+
private _Handlers;
|
|
37
|
+
constructor(level: LogLevel | LogLevelName, name?: string, options?: LoggerOptions);
|
|
38
|
+
get level(): LogLevel;
|
|
39
|
+
set level(value: LogLevel);
|
|
40
|
+
get levelName(): LogLevelName;
|
|
41
|
+
set levelName(value: LogLevelName);
|
|
42
|
+
get handlers(): LogHandler[];
|
|
43
|
+
addHandler(handler: LogHandler): void;
|
|
44
|
+
removeHandler(handler: LogHandler): void;
|
|
45
|
+
log<T>(level: LogLevel, msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[]): T | undefined;
|
|
46
|
+
error<T>(msg: () => T, ...args: unknown[]): T | undefined;
|
|
47
|
+
error<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
|
|
48
|
+
warn<T>(msg: () => T, ...args: unknown[]): T | undefined;
|
|
49
|
+
warn<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
|
|
50
|
+
info<T>(msg: () => T, ...args: unknown[]): T | undefined;
|
|
51
|
+
info<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
|
|
52
|
+
debug<T>(msg: () => T, ...args: unknown[]): T | undefined;
|
|
53
|
+
debug<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
|
|
54
|
+
private asString;
|
|
55
|
+
}
|
|
56
|
+
type GenericFunction = (...args: unknown[]) => unknown;
|
|
57
|
+
type FormatterFunction = (record: LogRecord) => string;
|
|
58
|
+
export interface LogRecord {
|
|
59
|
+
readonly date: Date;
|
|
60
|
+
readonly level: LogLevel;
|
|
61
|
+
readonly levelName: LogLevelName;
|
|
62
|
+
readonly logger: string;
|
|
63
|
+
readonly message: string;
|
|
64
|
+
readonly args: unknown[];
|
|
65
|
+
}
|
|
66
|
+
export declare const DEFAULT_FORMATTER: FormatterFunction;
|
|
67
|
+
export declare const PRETTY_FORMATTER: FormatterFunction;
|
|
68
|
+
export declare class LogHandler {
|
|
69
|
+
private _Level;
|
|
70
|
+
private _FormatterFn;
|
|
71
|
+
constructor(level: LogLevel | LogLevelName, formatter?: FormatterFunction);
|
|
72
|
+
get level(): LogLevel;
|
|
73
|
+
set level(value: LogLevel);
|
|
74
|
+
get levelName(): LogLevelName;
|
|
75
|
+
set levelName(value: LogLevelName);
|
|
76
|
+
handle(record: LogRecord): void;
|
|
77
|
+
log(formattedString: string, record: LogRecord): void;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function assert(condition: unknown, message: string): asserts condition;
|
|
2
|
+
export declare function fail(message: string): never;
|
|
3
|
+
export type Failure = {
|
|
4
|
+
type: "Failure";
|
|
5
|
+
reason: string;
|
|
6
|
+
};
|
|
7
|
+
export type Success<T> = {
|
|
8
|
+
type: "Success";
|
|
9
|
+
value: T;
|
|
10
|
+
};
|
|
11
|
+
export type Result<T> = Success<T> | Failure;
|
|
12
|
+
export declare function success<T>(value: T): Success<T>;
|
|
13
|
+
export declare function success(value: void): Success<void>;
|
|
14
|
+
export declare function failure(reason: string): Failure;
|
|
15
|
+
export declare function unwrap<T>(result: Result<T>): T;
|
|
16
|
+
export declare function unwrapOr<T>(result: Result<T>, fallback: T): T;
|
|
17
|
+
export type Accept<T> = (result: T) => void;
|
|
18
|
+
export type Reject = (reason: Error) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class Selector<T extends Array<() => PromiseLike<U>>, U> {
|
|
2
|
+
private readonly _Generators;
|
|
3
|
+
private readonly _Futures;
|
|
4
|
+
constructor(_Generators: T);
|
|
5
|
+
next(): Promise<Awaited<ReturnType<T[number]>>>;
|
|
6
|
+
static addIndex<T>(generator: () => PromiseLike<T>, index: number): Promise<[T, number]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function sleep(ms: number, value: void): Promise<void>;
|
|
2
|
+
export declare function sleep<T extends string>(ms: number, value: T): Promise<T>;
|
|
3
|
+
export declare function abortableSleep(ms: number, signal: AbortSignal): Promise<void | "aborted">;
|
|
4
|
+
export declare function nextTick(): Promise<void>;
|
package/utility/url.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Failure, Result, Success } from "./result.ts";
|
|
2
|
+
export declare function isProperty<T extends object>(object: T, name: string): name is Extract<keyof T, string>;
|
|
3
|
+
export declare function isFunction(value: unknown): value is (...args: [unknown]) => unknown;
|
|
4
|
+
export declare function isNull(value: unknown): boolean;
|
|
5
|
+
export declare function isNumber(value: unknown): value is number;
|
|
6
|
+
export declare function isObject(value: unknown): value is object;
|
|
7
|
+
export declare function isString(value: unknown): value is string;
|
|
8
|
+
export declare function isUndefined(value: unknown): value is undefined;
|
|
9
|
+
export declare function isFailure<T>(result: Result<T>): result is Failure;
|
|
10
|
+
export declare function isSuccess<T>(result: Result<T>): result is Success<T>;
|