@4players/odin-common 3.2.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/README.md +11 -5
- package/mod.d.ts +26 -0
- package/mod.js +1182 -0
- package/mod.mjs +1065 -0
- package/package.json +6 -30
- package/{lib/plugin → plugin}/api.d.ts +7 -7
- package/{lib/rpc → rpc}/commands.d.ts +99 -99
- package/rpc/notifications.d.ts +1626 -0
- package/{lib/schema → schema}/channels.d.ts +1 -1
- 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/{lib/schema → schema}/serialization.d.ts +2 -2
- package/{lib/schema → schema}/token.d.ts +31 -31
- package/{lib/schema → schema}/webrtc.d.ts +21 -21
- package/{lib/utility → utility}/base64.d.ts +1 -1
- package/utility/bytearray.d.ts +4 -0
- package/{lib/utility → utility}/codec.d.ts +1 -1
- package/utility/json.d.ts +2 -0
- package/{lib/utility → utility}/log.d.ts +3 -3
- package/{lib/utility → utility}/result.d.ts +2 -2
- package/{lib/utility → utility}/selector.d.ts +2 -2
- package/{lib/utility → utility}/sleep.d.ts +1 -1
- package/{lib/utility → utility}/url.d.ts +1 -1
- package/utility/validation.d.ts +10 -0
- package/eslint.config.mjs +0 -30
- package/lib/cjs/index.js +0 -44
- package/lib/cjs/plugin/api.js +0 -19
- package/lib/cjs/rpc/commands.js +0 -96
- package/lib/cjs/rpc/notifications.js +0 -39
- package/lib/cjs/schema/channels.js +0 -44
- package/lib/cjs/schema/media.js +0 -25
- package/lib/cjs/schema/message.js +0 -10
- package/lib/cjs/schema/peer.js +0 -34
- package/lib/cjs/schema/room.js +0 -136
- package/lib/cjs/schema/serialization.js +0 -15
- package/lib/cjs/schema/token.js +0 -33
- package/lib/cjs/schema/webrtc.js +0 -23
- package/lib/cjs/tsconfig.cjs.tsbuildinfo +0 -1
- package/lib/cjs/utility/base64.js +0 -29
- package/lib/cjs/utility/bytearray.js +0 -28
- package/lib/cjs/utility/codec.js +0 -89
- package/lib/cjs/utility/environment.js +0 -32
- package/lib/cjs/utility/iterable.js +0 -10
- package/lib/cjs/utility/json.js +0 -6
- package/lib/cjs/utility/log.js +0 -224
- package/lib/cjs/utility/msgpack.js +0 -11
- package/lib/cjs/utility/result.js +0 -31
- package/lib/cjs/utility/selector.js +0 -18
- package/lib/cjs/utility/sleep.js +0 -27
- package/lib/cjs/utility/strand.js +0 -38
- package/lib/cjs/utility/url.js +0 -27
- package/lib/cjs/utility/uuid.js +0 -11
- package/lib/cjs/utility/validation.js +0 -38
- package/lib/esm/index.js +0 -27
- package/lib/esm/plugin/api.js +0 -16
- package/lib/esm/rpc/commands.js +0 -93
- package/lib/esm/rpc/notifications.js +0 -36
- package/lib/esm/schema/channels.js +0 -40
- package/lib/esm/schema/media.js +0 -22
- package/lib/esm/schema/message.js +0 -7
- package/lib/esm/schema/peer.js +0 -31
- package/lib/esm/schema/room.js +0 -133
- package/lib/esm/schema/serialization.js +0 -12
- package/lib/esm/schema/token.js +0 -29
- package/lib/esm/schema/webrtc.js +0 -20
- package/lib/esm/tsconfig.esm.tsbuildinfo +0 -1
- package/lib/esm/utility/base64.js +0 -25
- package/lib/esm/utility/bytearray.js +0 -24
- package/lib/esm/utility/codec.js +0 -85
- package/lib/esm/utility/environment.js +0 -24
- package/lib/esm/utility/iterable.js +0 -7
- package/lib/esm/utility/json.js +0 -3
- package/lib/esm/utility/log.js +0 -210
- package/lib/esm/utility/msgpack.js +0 -7
- package/lib/esm/utility/result.js +0 -23
- package/lib/esm/utility/selector.js +0 -14
- package/lib/esm/utility/sleep.js +0 -22
- package/lib/esm/utility/strand.js +0 -34
- package/lib/esm/utility/url.js +0 -23
- package/lib/esm/utility/uuid.js +0 -7
- package/lib/esm/utility/validation.js +0 -27
- package/lib/index.d.ts +0 -27
- package/lib/rpc/notifications.d.ts +0 -1626
- package/lib/schema/media.d.ts +0 -122
- package/lib/schema/message.d.ts +0 -12
- package/lib/schema/peer.d.ts +0 -226
- package/lib/schema/room.d.ts +0 -1673
- package/lib/utility/bytearray.d.ts +0 -4
- package/lib/utility/json.d.ts +0 -4
- package/lib/utility/msgpack.d.ts +0 -2
- package/lib/utility/validation.d.ts +0 -10
- /package/{lib/utility → utility}/environment.d.ts +0 -0
- /package/{lib/utility → utility}/iterable.d.ts +0 -0
- /package/{lib/utility → utility}/strand.d.ts +0 -0
- /package/{lib/utility → utility}/uuid.d.ts +0 -0
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { assert, failure, success } from './result';
|
|
2
|
-
export function toBytes(value) {
|
|
3
|
-
try {
|
|
4
|
-
assert(value !== undefined, 'undefined cannot be converted to byte array');
|
|
5
|
-
assert(value !== null, 'null cannot be converted to byte array');
|
|
6
|
-
const json = JSON.stringify(value);
|
|
7
|
-
const decoder = new TextEncoder();
|
|
8
|
-
return success(decoder.encode(json));
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
return failure(String(error));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export function fromBytes(bytes) {
|
|
15
|
-
try {
|
|
16
|
-
assert(bytes.length > 0, 'empty byte array cannot be converted to value');
|
|
17
|
-
const json = new TextDecoder().decode(bytes);
|
|
18
|
-
const text = JSON.parse(json);
|
|
19
|
-
return success(text);
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
return failure(String(error));
|
|
23
|
-
}
|
|
24
|
-
}
|
package/lib/esm/utility/codec.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { failure, success, unwrapOr } from './result';
|
|
2
|
-
const validCodecs = ['VP8', 'VP9', 'AV1', 'H264'];
|
|
3
|
-
export class VideoCodec {
|
|
4
|
-
constructor(codec) {
|
|
5
|
-
this.codec = codec;
|
|
6
|
-
this.channels = 0;
|
|
7
|
-
this.clockRate = 90000;
|
|
8
|
-
}
|
|
9
|
-
isValid() {
|
|
10
|
-
return validCodecs.includes(this.codec);
|
|
11
|
-
}
|
|
12
|
-
isSupported() {
|
|
13
|
-
if (typeof RTCRtpReceiver === 'undefined' ||
|
|
14
|
-
typeof RTCRtpReceiver.getCapabilities === 'undefined') {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
const expectedMimeType = unwrapOr(this.getMimeType(), '').toLowerCase();
|
|
18
|
-
const expectedFmtpLine = new Set(unwrapOr(this.getSdpFmtpLine(), '')
|
|
19
|
-
.split(';')
|
|
20
|
-
.map((arg) => arg.trim().toLowerCase()));
|
|
21
|
-
return (RTCRtpReceiver.getCapabilities('video')?.codecs?.find((c) => {
|
|
22
|
-
const actualMimeType = c.mimeType.toLowerCase();
|
|
23
|
-
const actualFmtpLine = new Set((c.sdpFmtpLine ?? '')
|
|
24
|
-
.split(';')
|
|
25
|
-
.map((arg) => arg.trim().toLowerCase()));
|
|
26
|
-
if (expectedMimeType !== actualMimeType)
|
|
27
|
-
return false;
|
|
28
|
-
if (expectedFmtpLine.size !== actualFmtpLine.size)
|
|
29
|
-
return false;
|
|
30
|
-
for (let item of expectedFmtpLine) {
|
|
31
|
-
if (!actualFmtpLine.has(item))
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
}) ?? null);
|
|
36
|
-
}
|
|
37
|
-
getPayloadType() {
|
|
38
|
-
switch (this.codec) {
|
|
39
|
-
case 'VP8':
|
|
40
|
-
return success(96);
|
|
41
|
-
case 'VP9':
|
|
42
|
-
return success(98);
|
|
43
|
-
case 'AV1':
|
|
44
|
-
return success(41);
|
|
45
|
-
case 'H264':
|
|
46
|
-
return success(102);
|
|
47
|
-
default:
|
|
48
|
-
return failure('invalid video codec');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
getMimeType() {
|
|
52
|
-
switch (this.codec) {
|
|
53
|
-
case 'VP8':
|
|
54
|
-
return success('video/VP8');
|
|
55
|
-
case 'VP9':
|
|
56
|
-
return success('video/VP9');
|
|
57
|
-
case 'AV1':
|
|
58
|
-
return success('video/AV1');
|
|
59
|
-
case 'H264':
|
|
60
|
-
return success('video/H264');
|
|
61
|
-
default:
|
|
62
|
-
return failure('invalid video codec');
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
getSdpFmtpLine() {
|
|
66
|
-
switch (this.codec) {
|
|
67
|
-
case 'VP8':
|
|
68
|
-
return success('');
|
|
69
|
-
case 'VP9':
|
|
70
|
-
return success(
|
|
71
|
-
// using high-bit-depth variant profile
|
|
72
|
-
'profile-id=2');
|
|
73
|
-
case 'AV1':
|
|
74
|
-
return success(
|
|
75
|
-
// using baseline profile (https://aomediacodec.github.io/av1-rtp-spec/#72-sdp-parameters)
|
|
76
|
-
'level-idx=5;profile=0;tier=0');
|
|
77
|
-
case 'H264':
|
|
78
|
-
return success(
|
|
79
|
-
// using baseline profile
|
|
80
|
-
'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f');
|
|
81
|
-
default:
|
|
82
|
-
return failure('invalid video codec');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export function isAudioCapable() {
|
|
2
|
-
return typeof AudioContext !== 'undefined' && typeof Worker !== 'undefined';
|
|
3
|
-
}
|
|
4
|
-
export function isSharedArrayBufferCapable() {
|
|
5
|
-
return typeof SharedArrayBuffer !== 'undefined';
|
|
6
|
-
}
|
|
7
|
-
export function isBlinkBrowser() {
|
|
8
|
-
const pattern = /(apple)?webkit\/537\.36/i;
|
|
9
|
-
return (typeof window !== 'undefined' && pattern.test(window.navigator.userAgent));
|
|
10
|
-
}
|
|
11
|
-
export function isElectronBrowser() {
|
|
12
|
-
const pattern = /electron/i;
|
|
13
|
-
return (typeof window !== 'undefined' && pattern.test(window.navigator.userAgent));
|
|
14
|
-
}
|
|
15
|
-
export function isFirefoxBrowser() {
|
|
16
|
-
const pattern = /firefox|iceweasel|fxios/i;
|
|
17
|
-
return (typeof window !== 'undefined' && pattern.test(window.navigator.userAgent));
|
|
18
|
-
}
|
|
19
|
-
export function isSafariBrowser() {
|
|
20
|
-
if (isBlinkBrowser())
|
|
21
|
-
return false;
|
|
22
|
-
const pattern = /safari|applewebkit/i;
|
|
23
|
-
return (typeof window !== 'undefined' && pattern.test(window.navigator.userAgent));
|
|
24
|
-
}
|
package/lib/esm/utility/json.js
DELETED
package/lib/esm/utility/log.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { failure, success, unwrap } from './result';
|
|
2
|
-
import { isNumber } from './validation';
|
|
3
|
-
export var LogVerbosity;
|
|
4
|
-
(function (LogVerbosity) {
|
|
5
|
-
LogVerbosity[LogVerbosity["NONE"] = 0] = "NONE";
|
|
6
|
-
LogVerbosity[LogVerbosity["ERROR"] = 1] = "ERROR";
|
|
7
|
-
LogVerbosity[LogVerbosity["WARN"] = 2] = "WARN";
|
|
8
|
-
LogVerbosity[LogVerbosity["INFO"] = 3] = "INFO";
|
|
9
|
-
LogVerbosity[LogVerbosity["DEBUG"] = 4] = "DEBUG";
|
|
10
|
-
})(LogVerbosity || (LogVerbosity = {}));
|
|
11
|
-
export const LogLevels = Object.values(LogVerbosity).filter((key) => !isNaN(Number(key)));
|
|
12
|
-
export const LogLevelNames = Object.keys(LogVerbosity).filter((key) => isNaN(Number(key)));
|
|
13
|
-
export const LogSymbols = {
|
|
14
|
-
[LogVerbosity.NONE]: '⚫',
|
|
15
|
-
[LogVerbosity.ERROR]: '🔴',
|
|
16
|
-
[LogVerbosity.WARN]: '🟡',
|
|
17
|
-
[LogVerbosity.INFO]: '🔵',
|
|
18
|
-
[LogVerbosity.DEBUG]: '🟣',
|
|
19
|
-
};
|
|
20
|
-
export const LogFunctions = {
|
|
21
|
-
[LogVerbosity.NONE]: console.log,
|
|
22
|
-
[LogVerbosity.ERROR]: console.error,
|
|
23
|
-
[LogVerbosity.WARN]: console.warn,
|
|
24
|
-
[LogVerbosity.INFO]: console.info,
|
|
25
|
-
[LogVerbosity.DEBUG]: console.debug,
|
|
26
|
-
};
|
|
27
|
-
export function getLevelByName(name) {
|
|
28
|
-
const level = LogVerbosity[name];
|
|
29
|
-
if (level === undefined) {
|
|
30
|
-
return failure(`invalid log level name '${name}'; valid names are: ${LogLevelNames.join(', ')}`);
|
|
31
|
-
}
|
|
32
|
-
return success(level);
|
|
33
|
-
}
|
|
34
|
-
export function getLevelName(level) {
|
|
35
|
-
const name = LogVerbosity[level];
|
|
36
|
-
if (name === undefined) {
|
|
37
|
-
return failure(`invalid log level ${level}; valid levels are: ${LogLevels[0]}-${LogLevels[LogLevels.length - 1]}`);
|
|
38
|
-
}
|
|
39
|
-
return success(name);
|
|
40
|
-
}
|
|
41
|
-
const LOG_DEFAULT_ID = 'default';
|
|
42
|
-
const LOG_COLLECTION = new Map();
|
|
43
|
-
export function getLogger(name = LOG_DEFAULT_ID) {
|
|
44
|
-
let logger = LOG_COLLECTION.get(name);
|
|
45
|
-
if (!logger) {
|
|
46
|
-
logger = new Logger('WARN', name);
|
|
47
|
-
}
|
|
48
|
-
return logger;
|
|
49
|
-
}
|
|
50
|
-
export function error(msg, ...args) {
|
|
51
|
-
if (msg instanceof Function) {
|
|
52
|
-
return getLogger(LOG_DEFAULT_ID).error(msg, ...args);
|
|
53
|
-
}
|
|
54
|
-
return getLogger(LOG_DEFAULT_ID).error(msg, ...args);
|
|
55
|
-
}
|
|
56
|
-
export function warn(msg, ...args) {
|
|
57
|
-
if (msg instanceof Function) {
|
|
58
|
-
return getLogger(LOG_DEFAULT_ID).warn(msg, ...args);
|
|
59
|
-
}
|
|
60
|
-
return getLogger(LOG_DEFAULT_ID).warn(msg, ...args);
|
|
61
|
-
}
|
|
62
|
-
export function info(msg, ...args) {
|
|
63
|
-
if (msg instanceof Function) {
|
|
64
|
-
return getLogger(LOG_DEFAULT_ID).info(msg, ...args);
|
|
65
|
-
}
|
|
66
|
-
return getLogger(LOG_DEFAULT_ID).info(msg, ...args);
|
|
67
|
-
}
|
|
68
|
-
export function debug(msg, ...args) {
|
|
69
|
-
if (msg instanceof Function) {
|
|
70
|
-
return getLogger(LOG_DEFAULT_ID).debug(msg, ...args);
|
|
71
|
-
}
|
|
72
|
-
return getLogger(LOG_DEFAULT_ID).debug(msg, ...args);
|
|
73
|
-
}
|
|
74
|
-
export class Logger {
|
|
75
|
-
constructor(level, name, options) {
|
|
76
|
-
this.name = name ?? LOG_DEFAULT_ID;
|
|
77
|
-
if (isNumber(level)) {
|
|
78
|
-
this._Level = unwrap(getLevelByName(unwrap(getLevelName(level))));
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
this._Level = unwrap(getLevelByName(level));
|
|
82
|
-
}
|
|
83
|
-
this._Handlers = options?.handlers || [new LogHandler(level)];
|
|
84
|
-
LOG_COLLECTION.set(this.name, this);
|
|
85
|
-
}
|
|
86
|
-
get level() {
|
|
87
|
-
return this._Level;
|
|
88
|
-
}
|
|
89
|
-
set level(value) {
|
|
90
|
-
this.levelName = unwrap(getLevelName(value));
|
|
91
|
-
}
|
|
92
|
-
get levelName() {
|
|
93
|
-
return unwrap(getLevelName(this._Level));
|
|
94
|
-
}
|
|
95
|
-
set levelName(value) {
|
|
96
|
-
this._Level = unwrap(getLevelByName(value));
|
|
97
|
-
this._Handlers.forEach((handler) => (handler.level = this._Level));
|
|
98
|
-
}
|
|
99
|
-
get handlers() {
|
|
100
|
-
return this._Handlers;
|
|
101
|
-
}
|
|
102
|
-
addHandler(handler) {
|
|
103
|
-
this._Handlers.push(handler);
|
|
104
|
-
}
|
|
105
|
-
removeHandler(handler) {
|
|
106
|
-
const index = this._Handlers.indexOf(handler);
|
|
107
|
-
if (index !== -1)
|
|
108
|
-
this._Handlers.splice(index, 1);
|
|
109
|
-
}
|
|
110
|
-
log(level, msg, ...args) {
|
|
111
|
-
if (this.level < level) {
|
|
112
|
-
return msg instanceof Function ? undefined : msg;
|
|
113
|
-
}
|
|
114
|
-
let fnResult;
|
|
115
|
-
let message;
|
|
116
|
-
if (msg instanceof Function) {
|
|
117
|
-
fnResult = msg();
|
|
118
|
-
message = this.asString(fnResult);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
message = this.asString(msg);
|
|
122
|
-
}
|
|
123
|
-
this._Handlers.forEach((handler) => {
|
|
124
|
-
handler.handle({
|
|
125
|
-
date: new Date(),
|
|
126
|
-
level,
|
|
127
|
-
levelName: unwrap(getLevelName(level)),
|
|
128
|
-
logger: this.name,
|
|
129
|
-
message,
|
|
130
|
-
args,
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
return msg instanceof Function ? fnResult : msg;
|
|
134
|
-
}
|
|
135
|
-
error(msg, ...args) {
|
|
136
|
-
return this.log(LogVerbosity.ERROR, msg, ...args);
|
|
137
|
-
}
|
|
138
|
-
warn(msg, ...args) {
|
|
139
|
-
return this.log(LogVerbosity.WARN, msg, ...args);
|
|
140
|
-
}
|
|
141
|
-
info(msg, ...args) {
|
|
142
|
-
return this.log(LogVerbosity.INFO, msg, ...args);
|
|
143
|
-
}
|
|
144
|
-
debug(msg, ...args) {
|
|
145
|
-
return this.log(LogVerbosity.DEBUG, msg, ...args);
|
|
146
|
-
}
|
|
147
|
-
asString(data, isProperty = false) {
|
|
148
|
-
if (typeof data === 'string') {
|
|
149
|
-
if (isProperty)
|
|
150
|
-
return `"${data}"`;
|
|
151
|
-
return data;
|
|
152
|
-
}
|
|
153
|
-
else if (data === null ||
|
|
154
|
-
typeof data === 'number' ||
|
|
155
|
-
typeof data === 'bigint' ||
|
|
156
|
-
typeof data === 'boolean' ||
|
|
157
|
-
typeof data === 'undefined' ||
|
|
158
|
-
typeof data === 'symbol') {
|
|
159
|
-
return String(data);
|
|
160
|
-
}
|
|
161
|
-
else if (data instanceof Error) {
|
|
162
|
-
return data.stack;
|
|
163
|
-
}
|
|
164
|
-
else if (typeof data === 'object') {
|
|
165
|
-
return `{${Object.entries(data)
|
|
166
|
-
.map(([k, v]) => `"${k}":${this.asString(v, true)}`)
|
|
167
|
-
.join(',')}}`;
|
|
168
|
-
}
|
|
169
|
-
return 'undefined';
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
export const DEFAULT_FORMATTER = ({ message }) => message;
|
|
173
|
-
export const PRETTY_FORMATTER = (record) => {
|
|
174
|
-
const date = `[${record.date.toISOString()}]`;
|
|
175
|
-
const level = `[${record.levelName}]`;
|
|
176
|
-
const logger = record.logger !== LOG_DEFAULT_ID ? `[${record.logger}] ` : '';
|
|
177
|
-
const symbol = LogSymbols[record.level];
|
|
178
|
-
return `${date} ${symbol} ${level.padEnd(7, ' ')} ${logger}${record.message}`;
|
|
179
|
-
};
|
|
180
|
-
export class LogHandler {
|
|
181
|
-
constructor(level, formatter = DEFAULT_FORMATTER) {
|
|
182
|
-
if (isNumber(level)) {
|
|
183
|
-
this._Level = unwrap(getLevelByName(unwrap(getLevelName(level))));
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
this._Level = unwrap(getLevelByName(level));
|
|
187
|
-
}
|
|
188
|
-
this._FormatterFn = formatter;
|
|
189
|
-
}
|
|
190
|
-
get level() {
|
|
191
|
-
return this._Level;
|
|
192
|
-
}
|
|
193
|
-
set level(value) {
|
|
194
|
-
this.levelName = unwrap(getLevelName(value));
|
|
195
|
-
}
|
|
196
|
-
get levelName() {
|
|
197
|
-
return unwrap(getLevelName(this._Level));
|
|
198
|
-
}
|
|
199
|
-
set levelName(value) {
|
|
200
|
-
this._Level = unwrap(getLevelByName(value));
|
|
201
|
-
}
|
|
202
|
-
handle(record) {
|
|
203
|
-
if (this._Level < record.level)
|
|
204
|
-
return;
|
|
205
|
-
this.log(this._FormatterFn(record), record);
|
|
206
|
-
}
|
|
207
|
-
log(formattedString, record) {
|
|
208
|
-
LogFunctions[record.level](formattedString, ...record.args);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function assert(condition, message) {
|
|
2
|
-
if (!condition) {
|
|
3
|
-
fail(message);
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
export function fail(message) {
|
|
7
|
-
throw new Error(message);
|
|
8
|
-
}
|
|
9
|
-
export function success(value) {
|
|
10
|
-
return { type: 'Success', value };
|
|
11
|
-
}
|
|
12
|
-
export function failure(reason) {
|
|
13
|
-
return { type: 'Failure', reason };
|
|
14
|
-
}
|
|
15
|
-
export function unwrap(result) {
|
|
16
|
-
if (result.type === 'Failure') {
|
|
17
|
-
fail(result.reason);
|
|
18
|
-
}
|
|
19
|
-
return result.value;
|
|
20
|
-
}
|
|
21
|
-
export function unwrapOr(result, fallback) {
|
|
22
|
-
return result.type === 'Success' ? result.value : fallback;
|
|
23
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export class Selector {
|
|
2
|
-
constructor(_Generators) {
|
|
3
|
-
this._Generators = _Generators;
|
|
4
|
-
this._Futures = _Generators.map(Selector.addIndex);
|
|
5
|
-
}
|
|
6
|
-
async next() {
|
|
7
|
-
const [result, index] = await Promise.race(this._Futures);
|
|
8
|
-
this._Futures[index] = Selector.addIndex(this._Generators[index], index);
|
|
9
|
-
return result;
|
|
10
|
-
}
|
|
11
|
-
static async addIndex(generator, index) {
|
|
12
|
-
return [await generator(), index];
|
|
13
|
-
}
|
|
14
|
-
}
|
package/lib/esm/utility/sleep.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export function sleep(ms, value) {
|
|
2
|
-
if (ms <= 0) {
|
|
3
|
-
return Promise.resolve(value);
|
|
4
|
-
}
|
|
5
|
-
return new Promise((resolve) => setTimeout(() => resolve(value), ms));
|
|
6
|
-
}
|
|
7
|
-
export function abortableSleep(ms, signal) {
|
|
8
|
-
if (signal.aborted) {
|
|
9
|
-
return Promise.resolve('aborted');
|
|
10
|
-
}
|
|
11
|
-
return new Promise((resolve) => {
|
|
12
|
-
const onAbort = () => resolve('aborted');
|
|
13
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
14
|
-
setTimeout(() => {
|
|
15
|
-
signal.removeEventListener('abort', onAbort);
|
|
16
|
-
resolve(undefined);
|
|
17
|
-
}, ms);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
export function nextTick() {
|
|
21
|
-
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
22
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export class Strand {
|
|
2
|
-
constructor(...values) {
|
|
3
|
-
this._Tasks = [];
|
|
4
|
-
this._Running = false;
|
|
5
|
-
this._Values = values;
|
|
6
|
-
}
|
|
7
|
-
enqueue(task) {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
const wrapped = async () => {
|
|
10
|
-
try {
|
|
11
|
-
const result = await task(...this._Values);
|
|
12
|
-
resolve(result);
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
reject(error);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
this._Tasks.push(wrapped);
|
|
19
|
-
if (!this._Running) {
|
|
20
|
-
this.execute();
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
async execute() {
|
|
25
|
-
this._Running = true;
|
|
26
|
-
while (true) {
|
|
27
|
-
const task = this._Tasks.shift();
|
|
28
|
-
if (task === undefined)
|
|
29
|
-
break;
|
|
30
|
-
await task();
|
|
31
|
-
}
|
|
32
|
-
this._Running = false;
|
|
33
|
-
}
|
|
34
|
-
}
|
package/lib/esm/utility/url.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { failure, success } from './result';
|
|
2
|
-
export function normalizeUrl(url) {
|
|
3
|
-
let normalized = url.trim();
|
|
4
|
-
if (url.indexOf('://') === -1)
|
|
5
|
-
normalized = `https://${normalized}`;
|
|
6
|
-
try {
|
|
7
|
-
return success(new URL(normalized));
|
|
8
|
-
}
|
|
9
|
-
catch (error) {
|
|
10
|
-
return failure(String(error));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export function extendUrl(base, path) {
|
|
14
|
-
let pathname = base.pathname;
|
|
15
|
-
if (pathname.endsWith('/') === false)
|
|
16
|
-
pathname += '/';
|
|
17
|
-
try {
|
|
18
|
-
return success(new URL(pathname + path, base));
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
return failure(String(error));
|
|
22
|
-
}
|
|
23
|
-
}
|
package/lib/esm/utility/uuid.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export function isProperty(object, name) {
|
|
2
|
-
return name in object;
|
|
3
|
-
}
|
|
4
|
-
export function isFunction(value) {
|
|
5
|
-
return typeof value === 'function';
|
|
6
|
-
}
|
|
7
|
-
export function isNull(value) {
|
|
8
|
-
return typeof value === 'object' && value === null;
|
|
9
|
-
}
|
|
10
|
-
export function isNumber(value) {
|
|
11
|
-
return typeof value === 'number';
|
|
12
|
-
}
|
|
13
|
-
export function isObject(value) {
|
|
14
|
-
return typeof value === 'object';
|
|
15
|
-
}
|
|
16
|
-
export function isString(value) {
|
|
17
|
-
return typeof value === 'string';
|
|
18
|
-
}
|
|
19
|
-
export function isUndefined(value) {
|
|
20
|
-
return typeof value === 'undefined';
|
|
21
|
-
}
|
|
22
|
-
export function isFailure(result) {
|
|
23
|
-
return result.type === 'Failure';
|
|
24
|
-
}
|
|
25
|
-
export function isSuccess(result) {
|
|
26
|
-
return result.type === 'Success';
|
|
27
|
-
}
|
package/lib/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export * as zod from 'zod';
|
|
2
|
-
export * from './schema/serialization';
|
|
3
|
-
export * from './schema/token';
|
|
4
|
-
export * from './schema/room';
|
|
5
|
-
export * from './schema/peer';
|
|
6
|
-
export * from './schema/media';
|
|
7
|
-
export * from './schema/message';
|
|
8
|
-
export * from './schema/webrtc';
|
|
9
|
-
export * from './schema/channels';
|
|
10
|
-
export * from './rpc/commands';
|
|
11
|
-
export * from './rpc/notifications';
|
|
12
|
-
export * from './utility/base64';
|
|
13
|
-
export * from './utility/bytearray';
|
|
14
|
-
export * from './utility/codec';
|
|
15
|
-
export * from './utility/iterable';
|
|
16
|
-
export * from './utility/environment';
|
|
17
|
-
export * from './utility/json';
|
|
18
|
-
export * from './utility/msgpack';
|
|
19
|
-
export * from './utility/result';
|
|
20
|
-
export * from './utility/selector';
|
|
21
|
-
export * from './utility/sleep';
|
|
22
|
-
export * from './utility/strand';
|
|
23
|
-
export * from './utility/url';
|
|
24
|
-
export * from './utility/uuid';
|
|
25
|
-
export * from './utility/validation';
|
|
26
|
-
export * from './utility/log';
|
|
27
|
-
export * from './plugin/api';
|