@4players/odin-common 9.1.1 → 9.3.0
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 +36 -9
- package/{schema → api}/serialization.d.ts +1 -1
- package/cjs/mod.js +1 -1
- package/esm/mod.js +1 -1
- package/mod.d.ts +1 -11
- package/package.json +1 -1
- package/utility/bytearray.d.ts +1 -1
- package/utility/json.d.ts +1 -1
- package/utility/log.d.ts +31 -33
- package/rpc/commands.d.ts +0 -138
- package/rpc/notifications.d.ts +0 -276
- package/schema/channels.d.ts +0 -11
- package/schema/media.d.ts +0 -45
- package/schema/message.d.ts +0 -6
- package/schema/peer.d.ts +0 -54
- package/schema/room.d.ts +0 -350
- package/schema/token.d.ts +0 -31
- package/schema/webrtc.d.ts +0 -19
package/README.md
CHANGED
|
@@ -7,28 +7,55 @@
|
|
|
7
7
|
A collection of commonly used type definitions and schemas across ODIN web
|
|
8
8
|
projects.
|
|
9
9
|
|
|
10
|
+
## Entrypoints
|
|
11
|
+
|
|
12
|
+
The package is split into three entrypoints:
|
|
13
|
+
|
|
14
|
+
### `@4players/odin-common`
|
|
15
|
+
|
|
16
|
+
Lightweight utilities with no heavy dependencies. Includes logging, a `Result` type, video
|
|
17
|
+
codec helpers, async primitives (sleep, task queues, promise racing), base64/byte array encoding,
|
|
18
|
+
UUID generation, environment detection, type guards, URL helpers and the backend plugin API types.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { Logger, LogFilter } from '@4players/odin-common';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### `@4players/odin-common/api`
|
|
25
|
+
|
|
26
|
+
Zod-based schemas for the ODIN Voice protocol (rooms, peers, media, tokens, channels)
|
|
27
|
+
and RPC command/notification definitions. Importing from this entrypoint will pull in Zod.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { TokenClaims, TokenClaimsSchema } from '@4players/odin-common/api';
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### `@4players/odin-common/zod`
|
|
34
|
+
|
|
35
|
+
Re-exports the Zod library for consumers that need to create their own schemas without
|
|
36
|
+
adding a separate Zod dependency.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { zod } from '@4players/odin-common/zod';
|
|
40
|
+
```
|
|
41
|
+
|
|
10
42
|
## Troubleshooting
|
|
11
43
|
|
|
12
|
-
Contact us through the listed methods below to receive answers to your questions
|
|
13
|
-
and learn more about ODIN.
|
|
44
|
+
Contact us through the listed methods below to receive answers to your questions and learn more about ODIN.
|
|
14
45
|
|
|
15
46
|
### Discord
|
|
16
47
|
|
|
17
|
-
Join our official Discord server to chat with us directly and become a part of
|
|
18
|
-
the 4Players ODIN community.
|
|
48
|
+
Join our official Discord server to chat with us directly and become a part of the 4Players ODIN community.
|
|
19
49
|
|
|
20
50
|
[](https://4np.de/discord)
|
|
21
51
|
|
|
22
52
|
### Twitter
|
|
23
53
|
|
|
24
|
-
Have a quick question? Tweet us at
|
|
25
|
-
[@ODIN4Players](https://twitter.com/ODIN4Players) and we’ll help you resolve any
|
|
26
|
-
issues.
|
|
54
|
+
Have a quick question? Tweet us at [@ODIN4Players](https://twitter.com/ODIN4Players) and we’ll help you resolve any issues.
|
|
27
55
|
|
|
28
56
|
### Email
|
|
29
57
|
|
|
30
|
-
Don’t use Discord or Twitter? Send us an [email](mailto:odin@4players.io) and
|
|
31
|
-
we’ll get back to you as soon as possible.
|
|
58
|
+
Don’t use Discord or Twitter? Send us an [email](mailto:odin@4players.io) and we’ll get back to you as soon as possible.
|
|
32
59
|
|
|
33
60
|
[npm-badge-url]: https://www.npmjs.com/package/@4players/odin-common
|
|
34
61
|
[license-url]: https://github.com/4Players/odin-sdk-web/blob/master/LICENSE
|
|
@@ -3,7 +3,7 @@ export type RpcValue = Uint8Array | string | number | boolean | null | RpcValue[
|
|
|
3
3
|
[key: string]: RpcValue;
|
|
4
4
|
};
|
|
5
5
|
export type RpcSchema = z.ZodType<RpcValue, unknown>;
|
|
6
|
-
export declare const ByteArraySchema: z.ZodCustom<Uint8Array
|
|
6
|
+
export declare const ByteArraySchema: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
|
|
7
7
|
export type ByteArray = z.infer<typeof ByteArraySchema>;
|
|
8
8
|
declare const LiteralSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
|
|
9
9
|
type Literal = z.infer<typeof LiteralSchema>;
|
package/cjs/mod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ce=Object.create;var M=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Pe=Object.getPrototypeOf,Te=Object.prototype.hasOwnProperty;var Ae=(e,t)=>{for(var n in t)M(e,n,{get:t[n],enumerable:!0})},ee=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of Re(t))!Te.call(e,p)&&p!==n&&M(e,p,{get:()=>t[p],enumerable:!(o=ke(t,p))||o.enumerable});return e};var P=(e,t,n)=>(n=e!=null?Ce(Pe(e)):{},ee(t||!e||!e.__esModule?M(n,"default",{value:e,enumerable:!0}):n,e)),Le=e=>ee(M({},"__esModule",{value:!0}),e);var _t={};Ae(_t,{APM_DEFAULTS:()=>Nt,Backend:()=>ye,ByteArraySchema:()=>x,CONNECTION_STATS_INITIAL:()=>Mt,ChannelSet:()=>B,ChannelSetSchema:()=>K,ConsoleSink:()=>V,Formatter:()=>ge,GLOBAL_LOGGER:()=>R,JITTER_STATS_INITIAL:()=>jt,JsonSchema:()=>T,LogFilter:()=>F,LogLevel:()=>Q,LogSymbols:()=>fe,Logger:()=>C,MainCommandsRpc:()=>Ie,MainNotificationSchema:()=>Ee,MainNotificationsRpc:()=>De,MediaAudioPropertiesSchema:()=>ne,MediaIdSchema:()=>S,MediaPropertiesSchema:()=>j,MediaSchema:()=>U,MediaVideoPropertiesSchema:()=>oe,MessagePackRpcSchema:()=>Me,MessageReceivedSchema:()=>O,MinDBFS:()=>Mr,PeerIdSchema:()=>b,PeerPositionSchema:()=>L,PeerSchema:()=>N,PeerUpdateSchema:()=>_,RoomCommandsRpc:()=>Be,RoomNotificationSchema:()=>Fe,RoomNotificationsRpc:()=>Ve,RoomV1:()=>z,RoomV2:()=>ae,Selector:()=>$,Strand:()=>H,TokenAudienceSchema:()=>te,TokenClaimsSchema:()=>je,TokenSubjectSchema:()=>re,VAD_DEFAULTS:()=>Ut,VideoCodec:()=>G,WebRtcUpdateSchema:()=>k,abortableSleep:()=>nt,assert:()=>w,debug:()=>Lt,error:()=>Pt,extendUrl:()=>at,fail:()=>W,failure:()=>h,find:()=>He,fromBase64:()=>qe,fromBase64Url:()=>Ke,fromBytes:()=>Ge,generateUUID:()=>pt,info:()=>At,isAudioCapable:()=>Ze,isBlinkBrowser:()=>pe,isElectronBrowser:()=>Xe,isFailure:()=>xt,isFirefoxBrowser:()=>Qe,isFunction:()=>dt,isNull:()=>mt,isNumber:()=>lt,isObject:()=>ft,isProperty:()=>ut,isSafariBrowser:()=>et,isSharedArrayBufferCapable:()=>Ye,isString:()=>gt,isSuccess:()=>bt,isUndefined:()=>yt,log:()=>wt,nextTick:()=>ot,normalizeUrl:()=>it,oneOrMany:()=>A,parseCommand:()=>Ue,parseNotification:()=>Oe,parseRequest:()=>Ne,parseResponse:()=>_e,sleep:()=>rt,success:()=>y,toBytes:()=>We,toRaw:()=>tt,tryParseLogFilter:()=>kt,unwrap:()=>Je,unwrapOr:()=>E,validateUUID:()=>ct,warn:()=>Tt});module.exports=Le(_t);var m=require("zod"),x=m.z.custom(e=>e instanceof Uint8Array),we=m.z.union([m.z.string(),m.z.number(),m.z.boolean(),m.z.null()]),T=m.z.lazy(()=>m.z.union([we,m.z.array(T),m.z.record(m.z.string(),T)])),Me=m.z.union([m.z.tuple([m.z.literal(0),m.z.number(),m.z.string(),m.z.unknown()]),m.z.tuple([m.z.literal(1),m.z.number(),m.z.nullable(m.z.string()),m.z.unknown()]),m.z.tuple([m.z.literal(2),m.z.string(),m.z.unknown()])]);var u=require("zod"),te=u.z.enum(["sfu","gateway"]),re=u.z.enum(["connect","roomclose","roomupdate","roombanclient","roomsendmessage"]),je=u.z.object({uid:u.z.string(),cid:u.z.optional(u.z.string()),rid:A(u.z.string()).refine(e=>e.length>=1,{message:"missing rid"}),nsp:u.z.optional(u.z.string()),adr:u.z.optional(u.z.string()),aud:u.z.optional(A(te)),sub:u.z.optional(A(re)),exp:u.z.optional(u.z.number()),nbf:u.z.optional(u.z.number()),ups:u.z.optional(u.z.string()),tgs:u.z.optional(A(u.z.string())),tsp:u.z.optional(u.z.number()),internal:u.z.optional(u.z.object({server:u.z.optional(u.z.string())}))});function A(e){return u.z.union([e.transform(t=>[t]),u.z.array(e)])}var r=P(require("zod"));var d=P(require("zod")),S=d.number(),ne=d.object({kind:d.optional(d.literal("audio")),uid:d.optional(d.string()),customType:d.optional(d.string())}),oe=d.object({kind:d.optional(d.literal("video")),codec:d.optional(d.string()),uid:d.optional(d.string()),customType:d.optional(d.string()),id:d.optional(d.string())}),j=d.union([ne,oe]),U=d.object({id:S,properties:j,paused:d.boolean()});var l=P(require("zod"));var b=l.number(),L=l.union([l.tuple([l.number(),l.number(),l.number()]),l.tuple([l.number(),l.number()])]),N=l.object({id:b,user_id:l.string(),user_data:x,medias:l.array(U)}),_=l.discriminatedUnion("kind",[l.object({kind:l.literal("UserDataChanged"),peer_id:b,user_data:x}),l.object({kind:l.literal("MediaStarted"),peer_id:b,media:U}),l.object({kind:l.literal("MediaStopped"),peer_id:b,media_id:S})]);var ie=P(require("zod")),B=class e{constructor(t=BigInt(0)){this.value=t}from(...t){let n=t.reduce((o,p)=>o|I(p),BigInt(0));return new e(n)}contains(t){return(this.value&I(t))!==BigInt(0)}insert(t){this.value|=I(t)}remove(t){this.value&=~I(t)}[Symbol.iterator](){let t=-1,n=new e(this.value);return{next(){for(;t<63;)if(t+=1,n.contains(t))return{value:t,done:!1};return{value:void 0,done:!0}}}}},K=ie.bigint().transform(e=>new B(e));function I(e){return BigInt(1)<<BigInt(e)}var z;(c=>(c.RoomIdSchema=r.string(),c.RoomSchema=r.object({id:c.RoomIdSchema,customer:r.string(),user_data:x,peers:r.array(N)}),c.RoomUpdateSchema=r.discriminatedUnion("kind",[r.object({kind:r.literal("Joined"),room:c.RoomSchema,media_ids:r.array(S),own_peer_id:b}),r.object({kind:r.literal("Left"),reason:r.enum(["RoomClosing","ServerClosing","PeerKicked"])}),r.object({kind:r.literal("UserDataChanged"),user_data:r.optional(x)}),r.object({kind:r.literal("PeerJoined"),peer:N}),r.object({kind:r.literal("PeerLeft"),peer_id:b})]),c.RoomUpdatesSchema=r.object({updates:r.array(c.RoomUpdateSchema)}),c.RoomStatusSchema=r.enum(["Joining","Joined","Closed"]),c.RoomStatusChangedSchema=r.object({status:c.RoomStatusSchema,message:r.optional(r.string())})))(z||={});var ae;(a=>(a.ParametersSchema=r.record(r.string(),T),a.PeerProperties=r.object({user_data:x.optional(),tags:r.array(r.string()).optional(),audio_parameters:a.ParametersSchema.optional(),video_parameters:a.ParametersSchema.optional()}),a.PingSchema=r.object({Ping:r.object({id:r.number()})}),a.ChangeSelfSchema=r.object({ChangeSelf:a.PeerProperties.omit({tags:!0})}),a.SetAudioMaskSchema=r.object({SetAudioMask:r.object({peer_id:r.number(),mask:K})}),a.SendMessageSchema=r.object({SendMessage:r.object({peer_ids:r.number().array().default([]),message:x})}),a.CallSchema=a.PingSchema.or(a.ChangeSelfSchema).or(a.SetAudioMaskSchema).or(a.SendMessageSchema),a.PongSchema=r.object({Pong:r.object({id:r.number()})}),a.JoinedSchema=r.object({Joined:r.object({own_peer_id:r.number(),room_id:r.string(),customer:r.string()})}),a.LeftSchema=r.object({Left:r.object({reason:r.enum(["room_closing","server_closing","peer_kicked"])})}),a.PeerJoinedSchema=r.object({PeerJoined:a.PeerProperties.extend({peer_id:r.number(),user_id:r.string()})}),a.PeerLeftSchema=r.object({PeerLeft:r.object({peer_id:r.number()})}),a.PeerChangedSchema=r.object({PeerChanged:a.PeerProperties.extend({peer_id:r.number()})}),a.NewReconnectTokenSchema=r.object({NewReconnectToken:r.object({token:r.string()})}),a.MessageReceivedSchema=r.object({MessageReceived:r.object({sender_peer_id:r.number(),message:x})}),a.ErrorSchema=r.object({Error:r.object({message:x})}),a.EventSchema=a.PongSchema.or(a.JoinedSchema).or(a.LeftSchema).or(a.PeerJoinedSchema).or(a.PeerLeftSchema).or(a.PeerChangedSchema).or(a.NewReconnectTokenSchema).or(a.MessageReceivedSchema).or(a.ErrorSchema)))(ae||={});var se=require("zod");var O=se.z.object({sender_peer_id:b,message:x});var s=P(require("zod"));var k=s.discriminatedUnion("kind",[s.object({kind:s.literal("Sdp"),type:s.enum(["Answer","Offer"]),sdp:s.string(),media_map:s.array(s.tuple([S,s.string()]))}),s.object({kind:s.literal("Trickle"),candidate:s.string(),spd_mid:s.optional(s.string()),spd_mline_index:s.optional(s.number()),username_fragment:s.optional(s.union([s.string(),s.null()]))}),s.object({kind:s.literal("TrickleFinished")})]);var i=require("zod");function Ue(e,t,n){let o=n[e];if(!o)return;let p=o.request.safeParse(t);return p.success?{name:e,request:p.data}:void 0}function Ne(e,t,n){return n[e].request.parse(t)}function _e(e,t,n){let o=n[e].response.safeParse(t);return o.success?o.data:void 0}var Ie={Hello:{request:i.z.object({stream:i.z.literal("main")}),response:i.z.null()},JoinRoom:{request:i.z.object({token:i.z.string(),room_id:z.RoomIdSchema,user_data:x,position:L}),response:i.z.object({peer_id:b,stream_id:i.z.optional(i.z.number()),token:i.z.optional(i.z.string())})},WebRtcUpdate:{request:k,response:i.z.null()},RequestReconnectToken:{request:i.z.object({peer_id:i.z.optional(b)}),response:i.z.string()},Ping:{request:i.z.object({}),response:i.z.null()}},Be={Hello:{request:i.z.object({stream:i.z.literal("room"),token:i.z.string(),room_id:i.z.string(),user_data:x,position:L}),response:i.z.null()},UpdatePeer:{request:i.z.object({user_data:x}),response:i.z.null()},StartMedia:{request:i.z.object({media_id:S,properties:j}),response:i.z.null()},StopMedia:{request:i.z.object({media_id:S}),response:i.z.null()},PauseMedia:{request:i.z.object({media_id:S}),response:i.z.null()},ResumeMedia:{request:i.z.object({media_id:S}),response:i.z.null()},SetPeerPosition:{request:i.z.object({position:L}),response:i.z.null()},SendMessage:{request:i.z.object({target_peer_ids:i.z.optional(i.z.array(b)),message:x}),response:i.z.null()}};var v=require("zod");function Oe(e,t,n){let o=n[e];if(!o)return;let p=o.safeParse(t);return p.success?{name:e,properties:p.data}:void 0}var Ee=v.z.object({name:v.z.literal("WebRtcUpdate"),properties:k}),De={WebRtcUpdate:k},Fe=v.z.union([v.z.object({name:v.z.literal("RoomStatusChanged"),properties:z.RoomStatusChangedSchema}),v.z.object({name:v.z.literal("RoomUpdated"),properties:z.RoomUpdatesSchema}),v.z.object({name:v.z.literal("PeerUpdated"),properties:_}),v.z.object({name:v.z.literal("MessageReceived"),properties:O})]),Ve={RoomStatusChanged:z.RoomStatusChangedSchema,RoomUpdated:z.RoomUpdatesSchema,PeerUpdated:_,MessageReceived:O};function w(e,t){e||W(t)}function W(e){throw new Error(e)}function y(e){return{type:"Success",value:e}}function h(e){return{type:"Failure",reason:e}}function Je(e){return e.type==="Failure"&&W(e.reason),e.value}function E(e,t){return e.type==="Success"?e.value:t}function qe(e){try{let t=atob(e),n=Uint8Array.from(t,p=>p.codePointAt(0)),o=new TextDecoder("utf8");return y(o.decode(n))}catch(t){return h(String(t))}}function Ke(e){try{let t=atob(e.replace(/-/g,"+").replace(/_/g,"/")),n=Uint8Array.from(t,p=>p.codePointAt(0)),o=new TextDecoder("utf8");return y(o.decode(n))}catch(t){return h(String(t))}}function We(e){try{w(e!==void 0,"undefined cannot be converted to byte array"),w(e!==null,"null cannot be converted to byte array");let t=JSON.stringify(e),n=new TextEncoder;return y(n.encode(t))}catch(t){return h(String(t))}}function Ge(e){try{w(e.length>0,"empty byte array cannot be converted to value");let t=new TextDecoder().decode(e),n=JSON.parse(t);return y(n)}catch(t){return h(String(t))}}var $e=["VP8","VP9","AV1","H264"],G=class{constructor(t){this.codec=t}channels=0;clockRate=9e4;isValid(){return $e.includes(this.codec)}isSupported(){if(typeof RTCRtpReceiver>"u"||typeof RTCRtpReceiver.getCapabilities>"u")return null;let t=E(this.getMimeType(),"").toLowerCase(),n=new Set(E(this.getSdpFmtpLine(),"").split(";").map(o=>o.trim().toLowerCase()));return RTCRtpReceiver.getCapabilities("video")?.codecs?.find(o=>{let p=o.mimeType.toLowerCase(),f=new Set((o.sdpFmtpLine??"").split(";").map(c=>c.trim().toLowerCase()));if(t!==p||n.size!==f.size)return!1;for(let c of n)if(!f.has(c))return!1;return!0})??null}getPayloadType(){switch(this.codec){case"VP8":return y(96);case"VP9":return y(98);case"AV1":return y(41);case"H264":return y(102);default:return h("invalid video codec")}}getMimeType(){switch(this.codec){case"VP8":return y("video/VP8");case"VP9":return y("video/VP9");case"AV1":return y("video/AV1");case"H264":return y("video/H264");default:return h("invalid video codec")}}getSdpFmtpLine(){switch(this.codec){case"VP8":return y("");case"VP9":return y("profile-id=2");case"AV1":return y("level-idx=5;profile=0;tier=0");case"H264":return y("level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f");default:return h("invalid video codec")}}};function He(e,t){for(let n of e)if(t(n))return n}function Ze(){return typeof AudioContext<"u"&&typeof Worker<"u"}function Ye(){return typeof SharedArrayBuffer<"u"}function pe(){return/(apple)?webkit\/537\.36/i.test(globalThis.navigator.userAgent)}function Xe(){return/electron/i.test(globalThis.navigator.userAgent)}function Qe(){return/firefox|iceweasel|fxios/i.test(globalThis.navigator.userAgent)}function et(){return pe()?!1:/safari|applewebkit/i.test(globalThis.navigator.userAgent)}function tt(e){return JSON.parse(JSON.stringify(e))}var $=class e{constructor(t){this._Generators=t;this._Futures=t.map(e.addIndex)}_Futures;async next(){let[t,n]=await Promise.race(this._Futures);return this._Futures[n]=e.addIndex(this._Generators[n],n),t}static async addIndex(t,n){return[await t(),n]}};function rt(e,t){return e<=0?Promise.resolve(t):new Promise(n=>setTimeout(()=>n(t),e))}function nt(e,t){return t.aborted?Promise.resolve("aborted"):new Promise(n=>{let o=()=>n("aborted");t.addEventListener("abort",o,{once:!0}),setTimeout(()=>{t.removeEventListener("abort",o),n(void 0)},e)})}function ot(){return new Promise(e=>setTimeout(e,0))}var H=class{_Tasks=[];_Running=!1;_Values;constructor(...t){this._Values=t}enqueue(t){return new Promise((n,o)=>{let p=async()=>{try{let f=await t(...this._Values);n(f)}catch(f){o(f)}};this._Tasks.push(p),this._Running||this.execute()})}async execute(){for(this._Running=!0;;){let t=this._Tasks.shift();if(t===void 0)break;await t()}this._Running=!1}};function it(e){let t=e.trim();e.indexOf("://")===-1&&(t=`https://${t}`);try{return y(new URL(t))}catch(n){return h(String(n))}}function at(e,t){let n=e.pathname;n.endsWith("/")===!1&&(n+="/");try{return y(new URL(n+t,e))}catch(o){return h(String(o))}}var st=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function pt(){return crypto.randomUUID()}function ct(e){return st.test(e)}function ut(e,t){return t in e}function dt(e){return typeof e=="function"}function mt(e){return typeof e=="object"&&e===null}function lt(e){return typeof e=="number"}function ft(e){return typeof e=="object"}function gt(e){return typeof e=="string"}function yt(e){return typeof e>"u"}function xt(e){return e.type==="Failure"}function bt(e){return e.type==="Success"}var{Deno:ce}=globalThis,ht=typeof ce?.noColor=="boolean"?ce.noColor:!1,St=!ht;function Z(e,t){return{open:`\x1B[${e.join(";")}m`,close:`\x1B[${t}m`,regexp:new RegExp(`\\x1b\\[${t}m`,"g")}}function Y(e,t){return St?`${t.open}${e.replace(t.regexp,t.open)}${t.close}`:e}function D(e){return Y(e,Z([0],0))}function X(e){return Y(e,Z([1],22))}function ue(e){return Y(e,Z([2],22))}var Lr=new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TXZcf-nq-uy=><~]))"].join("|"),"g");var F=(g=>(g[g.Nothing=0]="Nothing",g[g.CRITICAL=1]="CRITICAL",g[g.ERROR=2]="ERROR",g[g.WARN=3]="WARN",g[g.INFO=4]="INFO",g[g.DEBUG=5]="DEBUG",g[g.Everything=6]="Everything",g))(F||{}),zt=new Date,Q=(f=>(f[f.CRITICAL=1]="CRITICAL",f[f.ERROR=2]="ERROR",f[f.WARN=3]="WARN",f[f.INFO=4]="INFO",f[f.DEBUG=5]="DEBUG",f))(Q||{}),fe={1:"\u{1F4A5}",2:"\u{1F534}",3:"\u{1F7E1}",4:"\u{1F535}",5:"\u{1F7E3}"},Ct={5:ue,4:D,3:D,2:X,1:X};function kt(e){for(let t of Object.keys(F))if(isNaN(Number(t))!==!1&&t.localeCompare(e,void 0,{sensitivity:"accent"})===0)return F[t]}function Rt({message:e}){return String(e)}function de(e){return JSON.stringify({timestamp:e.date.toISOString(),level:Q[e.level],message:e.message,extra:e.extra})}function me(e){function t(c,g){return[Math.floor(c/g),c%g]}function n(){let c,g=e.date.valueOf()-zt.valueOf();[g,c]=t(g,1e3);let[J,q]=t(g,60);return`${J.toString().padStart(4,"0")}:${q.toString().padStart(2,"0")}.${c.toString().padStart(4,"0")}`}function o(){return e.extra===void 0?"":"Deno"in globalThis?" "+Deno.inspect(e.extra,{compact:!1,colors:!0,trailingComma:!0}).trimStart():" "+JSON.stringify(e.extra)}let p=fe[e.level],f=e.logger.name!==void 0?`@${e.logger}`:"";return`${D(n())}${f} ${p} ${Ct[e.level](String(e.message))}${o()}`}var ge={sparse:Rt,json:de,pretty:me,default:"Deno"in globalThis&&Deno.stdout.isTerminal()?me:de},V=class{#e;#t;filter;constructor(t=ge.default,n=6,o=console){this.filter=n,this.#e=t,this.#t=o}handle(t){let n=this.#e(t);switch(t.level){case 2:this.#t.error(n);break;case 3:this.#t.warn(n);break;case 4:this.#t.info(n);break;case 5:this.#t.debug(n);break}}},C=class{#e;sinks;filter;get name(){return this.#e}constructor(t,n=void 0,o=[new V]){this.#e=n,this.sinks=o,this.filter=t}log(t,n,o=void 0){if(this.filter<t)return;let p=le;for(let f of this.sinks)f.filter<t||(p===le&&(p={date:new Date,level:t,logger:this,message:typeof n=="function"?n():n,extra:o}),f.handle(p))}error=this.log.bind(this,2);warn=this.log.bind(this,3);info=this.log.bind(this,4);debug=this.log.bind(this,5)},R=new C(4),Pt=C.prototype.log.bind(R,2),Tt=C.prototype.log.bind(R,3),At=C.prototype.log.bind(R,4),Lt=C.prototype.log.bind(R,5),wt=C.prototype.log.bind(R),le=Symbol();var Mr=-758.596,ye;(t=>{let e;(c=>(c[c.InvalidPassword=-1]="InvalidPassword",c[c.Unknown=0]="Unknown",c[c.Unencrypted=1]="Unencrypted",c[c.Encrypted=2]="Encrypted"))(e=t.PeerCipherStatus||={})})(ye||={});var Mt={bytesSent:0,bytesReceived:0,packetsSent:0,packetsReceived:0,rtt:0,packetLoss:0},jt={packetsBuffered:0,packetsSeen:0,packetsProcessed:0,packetsTooEarly:0,packetsTooLate:0,packetsDropped:0,packetsInvalid:0,packetsRepeated:0,packetsLost:0},Ut={voiceActivity:{attackThreshold:.9,releaseThreshold:.8},volumeGate:{attackThreshold:-30,releaseThreshold:-40}},Nt={echoCanceller:!0,highPassFilter:!1,noiseSuppression:"Moderate",transientSuppressor:!1,gainController:!0};0&&(module.exports={APM_DEFAULTS,Backend,ByteArraySchema,CONNECTION_STATS_INITIAL,ChannelSet,ChannelSetSchema,ConsoleSink,Formatter,GLOBAL_LOGGER,JITTER_STATS_INITIAL,JsonSchema,LogFilter,LogLevel,LogSymbols,Logger,MainCommandsRpc,MainNotificationSchema,MainNotificationsRpc,MediaAudioPropertiesSchema,MediaIdSchema,MediaPropertiesSchema,MediaSchema,MediaVideoPropertiesSchema,MessagePackRpcSchema,MessageReceivedSchema,MinDBFS,PeerIdSchema,PeerPositionSchema,PeerSchema,PeerUpdateSchema,RoomCommandsRpc,RoomNotificationSchema,RoomNotificationsRpc,RoomV1,RoomV2,Selector,Strand,TokenAudienceSchema,TokenClaimsSchema,TokenSubjectSchema,VAD_DEFAULTS,VideoCodec,WebRtcUpdateSchema,abortableSleep,assert,debug,error,extendUrl,fail,failure,find,fromBase64,fromBase64Url,fromBytes,generateUUID,info,isAudioCapable,isBlinkBrowser,isElectronBrowser,isFailure,isFirefoxBrowser,isFunction,isNull,isNumber,isObject,isProperty,isSafariBrowser,isSharedArrayBufferCapable,isString,isSuccess,isUndefined,log,nextTick,normalizeUrl,oneOrMany,parseCommand,parseNotification,parseRequest,parseResponse,sleep,success,toBytes,toRaw,tryParseLogFilter,unwrap,unwrapOr,validateUUID,warn});
|
|
1
|
+
var y=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var r in t)y(e,r,{get:t[r],enumerable:!0})},j=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of U(t))!N.call(e,s)&&s!==r&&y(e,s,{get:()=>t[s],enumerable:!(n=F(t,s))||n.enumerable});return e};var _=e=>j(y({},"__esModule",{value:!0}),e);var Ee={};M(Ee,{APM_DEFAULTS:()=>W,Backend:()=>P,CONNECTION_STATS_INITIAL:()=>$,ConsoleSink:()=>f,Formatter:()=>B,GLOBAL_LOGGER:()=>d,InteractiveConsoleSink:()=>C,JITTER_STATS_INITIAL:()=>J,LogLevel:()=>p,LogSymbols:()=>S,Logger:()=>c,MinDBFS:()=>Ue,Selector:()=>h,Strand:()=>L,VAD_DEFAULTS:()=>G,VideoCodec:()=>v,abortableSleep:()=>se,assert:()=>g,debug:()=>Be,error:()=>Ve,extendUrl:()=>ce,fail:()=>x,failure:()=>u,find:()=>K,fromBase64:()=>z,fromBase64Url:()=>Z,fromBytes:()=>Y,generateUUID:()=>pe,info:()=>De,isAudioCapable:()=>Q,isBlinkBrowser:()=>A,isElectronBrowser:()=>te,isFailure:()=>he,isFirefoxBrowser:()=>re,isFunction:()=>fe,isNull:()=>me,isNumber:()=>be,isObject:()=>ye,isProperty:()=>ge,isSafariBrowser:()=>ne,isSharedArrayBufferCapable:()=>ee,isString:()=>xe,isSuccess:()=>Le,isUndefined:()=>ve,log:()=>Ie,nextTick:()=>ae,normalizeUrl:()=>ue,sleep:()=>ie,success:()=>o,toBytes:()=>q,toRaw:()=>oe,tryParseLogLevel:()=>Pe,unwrap:()=>H,unwrapOr:()=>m,validateUUID:()=>de,warn:()=>Oe});module.exports=_(Ee);var Ue=-758.596,P;(t=>{let e;(a=>(a[a.InvalidPassword=-1]="InvalidPassword",a[a.Unknown=0]="Unknown",a[a.Unencrypted=1]="Unencrypted",a[a.Encrypted=2]="Encrypted"))(e=t.PeerCipherStatus||={})})(P||={});var $={bytesSent:0,bytesReceived:0,packetsSent:0,packetsReceived:0,rtt:0,packetLoss:0},J={packetsBuffered:0,packetsSeen:0,packetsProcessed:0,packetsTooEarly:0,packetsTooLate:0,packetsDropped:0,packetsInvalid:0,packetsRepeated:0,packetsLost:0},G={voiceActivity:{attackThreshold:.9,releaseThreshold:.8},volumeGate:{attackThreshold:-30,releaseThreshold:-40}},W={echoCanceller:!0,highPassFilter:!1,noiseSuppression:"Moderate",transientSuppressor:!1,gainController:!0};function g(e,t){e||x(t)}function x(e){throw new Error(e)}function o(e){return{type:"Success",value:e}}function u(e){return{type:"Failure",reason:e}}function H(e){return e.type==="Failure"&&x(e.reason),e.value}function m(e,t){return e.type==="Success"?e.value:t}function z(e){try{let t=atob(e),r=Uint8Array.from(t,s=>s.codePointAt(0)),n=new TextDecoder("utf8");return o(n.decode(r))}catch(t){return u(String(t))}}function Z(e){try{let t=atob(e.replace(/-/g,"+").replace(/_/g,"/")),r=Uint8Array.from(t,s=>s.codePointAt(0)),n=new TextDecoder("utf8");return o(n.decode(r))}catch(t){return u(String(t))}}function q(e){try{g(e!==void 0,"undefined cannot be converted to byte array"),g(e!==null,"null cannot be converted to byte array");let t=JSON.stringify(e),r=new TextEncoder;return o(r.encode(t))}catch(t){return u(String(t))}}function Y(e){try{g(e.length>0,"empty byte array cannot be converted to value");let t=new TextDecoder().decode(e),r=JSON.parse(t);return o(r)}catch(t){return u(String(t))}}var X=["VP8","VP9","AV1","H264"],v=class{constructor(t){this.codec=t}channels=0;clockRate=9e4;isValid(){return X.includes(this.codec)}isSupported(){if(typeof RTCRtpReceiver>"u"||typeof RTCRtpReceiver.getCapabilities>"u")return null;let t=m(this.getMimeType(),"").toLowerCase(),r=new Set(m(this.getSdpFmtpLine(),"").split(";").map(n=>n.trim().toLowerCase()));return RTCRtpReceiver.getCapabilities("video")?.codecs?.find(n=>{let s=n.mimeType.toLowerCase(),i=new Set((n.sdpFmtpLine??"").split(";").map(a=>a.trim().toLowerCase()));if(t!==s||r.size!==i.size)return!1;for(let a of r)if(!i.has(a))return!1;return!0})??null}getPayloadType(){switch(this.codec){case"VP8":return o(96);case"VP9":return o(98);case"AV1":return o(41);case"H264":return o(102);default:return u("invalid video codec")}}getMimeType(){switch(this.codec){case"VP8":return o("video/VP8");case"VP9":return o("video/VP9");case"AV1":return o("video/AV1");case"H264":return o("video/H264");default:return u("invalid video codec")}}getSdpFmtpLine(){switch(this.codec){case"VP8":return o("");case"VP9":return o("profile-id=2");case"AV1":return o("level-idx=5;profile=0;tier=0");case"H264":return o("level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f");default:return u("invalid video codec")}}};function K(e,t){for(let r of e)if(t(r))return r}function Q(){return typeof AudioContext<"u"&&typeof Worker<"u"}function ee(){return typeof SharedArrayBuffer<"u"}function A(){return/(apple)?webkit\/537\.36/i.test(globalThis.navigator.userAgent)}function te(){return/electron/i.test(globalThis.navigator.userAgent)}function re(){return/firefox|iceweasel|fxios/i.test(globalThis.navigator.userAgent)}function ne(){return A()?!1:/safari|applewebkit/i.test(globalThis.navigator.userAgent)}function oe(e){return JSON.parse(JSON.stringify(e))}var h=class e{constructor(t){this._Generators=t;this._Futures=t.map(e.addIndex)}_Futures;async next(){let[t,r]=await Promise.race(this._Futures);return this._Futures[r]=e.addIndex(this._Generators[r],r),t}static async addIndex(t,r){return[await t(),r]}};function ie(e,t){return e<=0?Promise.resolve(t):new Promise(r=>setTimeout(()=>r(t),e))}function se(e,t){return t.aborted?Promise.resolve("aborted"):new Promise(r=>{let n=()=>r("aborted");t.addEventListener("abort",n,{once:!0}),setTimeout(()=>{t.removeEventListener("abort",n),r(void 0)},e)})}function ae(){return new Promise(e=>setTimeout(e,0))}var L=class{_Tasks=[];_Running=!1;_Values;constructor(...t){this._Values=t}enqueue(t){return new Promise((r,n)=>{let s=async()=>{try{let i=await t(...this._Values);r(i)}catch(i){n(i)}};this._Tasks.push(s),this._Running||this.execute()})}async execute(){for(this._Running=!0;;){let t=this._Tasks.shift();if(t===void 0)break;await t()}this._Running=!1}};function ue(e){let t=e.trim();e.indexOf("://")===-1&&(t=`https://${t}`);try{return o(new URL(t))}catch(r){return u(String(r))}}function ce(e,t){let r=e.pathname;r.endsWith("/")===!1&&(r+="/");try{return o(new URL(r+t,e))}catch(n){return u(String(n))}}var le=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function pe(){return crypto.randomUUID()}function de(e){return le.test(e)}function ge(e,t){return t in e}function fe(e){return typeof e=="function"}function me(e){return typeof e=="object"&&e===null}function be(e){return typeof e=="number"}function ye(e){return typeof e=="object"}function xe(e){return typeof e=="string"}function ve(e){return typeof e>"u"}function he(e){return e.type==="Failure"}function Le(e){return e.type==="Success"}var{Deno:w}=globalThis,Re=typeof w?.noColor=="boolean"?w.noColor:!1,Te=!Re;function R(e,t){return{open:`\x1B[${e.join(";")}m`,close:`\x1B[${t}m`,regexp:new RegExp(`\\x1b\\[${t}m`,"g")}}function T(e,t){return Te?`${t.open}${e.replace(t.regexp,t.open)}${t.close}`:e}function b(e){return T(e,R([0],0))}function k(e){return T(e,R([1],22))}function V(e){return T(e,R([2],22))}var rt=new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TXZcf-nq-uy=><~]))"].join("|"),"g");var Ce=new Date,p=(i=>(i[i.CRITICAL=0]="CRITICAL",i[i.ERROR=1]="ERROR",i[i.WARN=2]="WARN",i[i.INFO=3]="INFO",i[i.DEBUG=4]="DEBUG",i))(p||{}),S={0:"\u{1F4A5}",1:"\u{1F534}",2:"\u{1F7E1}",3:"\u{1F535}",4:"\u{1F7E3}"},Se={4:V,3:b,2:b,1:k,0:k};function Pe(e){for(let t of Object.keys(p))if(isNaN(Number(t))!==!1&&t.localeCompare(e,void 0,{sensitivity:"accent"})===0)return p[t]}function Ae({message:e}){return String(e)}function O(e){return JSON.stringify({timestamp:e.date.toISOString(),level:p[e.level],message:e.message,extra:e.extra})}function D(e){function t(a,l){return[Math.floor(a/l),a%l]}function r(){let a,l=e.date.valueOf()-Ce.valueOf();[l,a]=t(l,1e3);let[I,E]=t(l,60);return`${I.toString().padStart(4,"0")}:${E.toString().padStart(2,"0")}.${a.toString().padStart(4,"0")}`}function n(){return e.extra===void 0?"":"Deno"in globalThis?" "+Deno.inspect(e.extra,{compact:!1,colors:!0,trailingComma:!0}).trimStart():" "+JSON.stringify(e.extra)}let s=S[e.level],i=e.logger.name!==void 0?`@${e.logger}`:"";return`${b(r())}${i} ${s} ${Se[e.level](String(e.message))}${n()}`}function we(e){let t=`[${e.date.toISOString()}]`,r=`[${p[e.level]}]`,n=e.logger.name!==void 0?`[${e.logger.name}] `:"",s=S[e.level];return`${t} ${s} ${r.padEnd(7," ")} ${n}${e.message}`}var B={sparse:Ae,json:O,pretty:D,structured:we,default:"Deno"in globalThis&&Deno.stdout.isTerminal()?D:O},f=class{formatter;consoleObject;filter;constructor(t=B.default,r=4,n=console){this.filter=r,this.formatter=t,this.consoleObject=n}handle(t){let r=this.formatter(t);switch(t.level){case 1:this.consoleObject.error(r);break;case 2:this.consoleObject.warn(r);break;case 3:this.consoleObject.info(r);break;case 4:this.consoleObject.debug(r);break}}},C=class extends f{handle(t){let r=this.formatter(t),n=t.extra!==void 0?[r,t.extra]:[r];switch(t.level){case 0:case 1:this.consoleObject.error(...n);break;case 2:this.consoleObject.warn(...n);break;case 3:this.consoleObject.info(...n);break;case 4:this.consoleObject.debug(...n);break}}},c=class{#e;sinks;filter;parent;get name(){return this.#e}constructor(t,r=void 0,n=[],s=void 0){this.#e=r,this.sinks=n,this.filter=t,this.parent=s}log(t,r,n=void 0){let i={date:new Date,level:t,logger:this,message:r,extra:n};this.filter<t||this.insert(i)}insert(t){if(!(this.filter<t.level)){for(let r of this.sinks)r.filter>=t.level&&r.handle(t);this.parent!==void 0&&this.parent.insert(t)}}error=this.log.bind(this,1);warn=this.log.bind(this,2);info=this.log.bind(this,3);debug=this.log.bind(this,4)},d=new c(3,void 0,[new f]),Ve=c.prototype.log.bind(d,1),Oe=c.prototype.log.bind(d,2),De=c.prototype.log.bind(d,3),Be=c.prototype.log.bind(d,4),Ie=c.prototype.log.bind(d);0&&(module.exports={APM_DEFAULTS,Backend,CONNECTION_STATS_INITIAL,ConsoleSink,Formatter,GLOBAL_LOGGER,InteractiveConsoleSink,JITTER_STATS_INITIAL,LogLevel,LogSymbols,Logger,MinDBFS,Selector,Strand,VAD_DEFAULTS,VideoCodec,abortableSleep,assert,debug,error,extendUrl,fail,failure,find,fromBase64,fromBase64Url,fromBytes,generateUUID,info,isAudioCapable,isBlinkBrowser,isElectronBrowser,isFailure,isFirefoxBrowser,isFunction,isNull,isNumber,isObject,isProperty,isSafariBrowser,isSharedArrayBufferCapable,isString,isSuccess,isUndefined,log,nextTick,normalizeUrl,sleep,success,toBytes,toRaw,tryParseLogLevel,unwrap,unwrapOr,validateUUID,warn});
|
package/esm/mod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as d}from"zod";var x=d.custom(e=>e instanceof Uint8Array),ue=d.union([d.string(),d.number(),d.boolean(),d.null()]),P=d.lazy(()=>d.union([ue,d.array(P),d.record(d.string(),P)])),Me=d.union([d.tuple([d.literal(0),d.number(),d.string(),d.unknown()]),d.tuple([d.literal(1),d.number(),d.nullable(d.string()),d.unknown()]),d.tuple([d.literal(2),d.string(),d.unknown()])]);import{z as c}from"zod";var de=c.enum(["sfu","gateway"]),me=c.enum(["connect","roomclose","roomupdate","roombanclient","roomsendmessage"]),Ne=c.object({uid:c.string(),cid:c.optional(c.string()),rid:T(c.string()).refine(e=>e.length>=1,{message:"missing rid"}),nsp:c.optional(c.string()),adr:c.optional(c.string()),aud:c.optional(T(de)),sub:c.optional(T(me)),exp:c.optional(c.number()),nbf:c.optional(c.number()),ups:c.optional(c.string()),tgs:c.optional(T(c.string())),tsp:c.optional(c.number()),internal:c.optional(c.object({server:c.optional(c.string())}))});function T(e){return c.union([e.transform(t=>[t]),c.array(e)])}import*as r from"zod";import*as u from"zod";var S=u.number(),le=u.object({kind:u.optional(u.literal("audio")),uid:u.optional(u.string()),customType:u.optional(u.string())}),fe=u.object({kind:u.optional(u.literal("video")),codec:u.optional(u.string()),uid:u.optional(u.string()),customType:u.optional(u.string()),id:u.optional(u.string())}),N=u.union([le,fe]),_=u.object({id:S,properties:N,paused:u.boolean()});import*as m from"zod";var b=m.number(),A=m.union([m.tuple([m.number(),m.number(),m.number()]),m.tuple([m.number(),m.number()])]),I=m.object({id:b,user_id:m.string(),user_data:x,medias:m.array(_)}),B=m.discriminatedUnion("kind",[m.object({kind:m.literal("UserDataChanged"),peer_id:b,user_data:x}),m.object({kind:m.literal("MediaStarted"),peer_id:b,media:_}),m.object({kind:m.literal("MediaStopped"),peer_id:b,media_id:S})]);import*as W from"zod";var O=class e{constructor(t=BigInt(0)){this.value=t}from(...t){let n=t.reduce((o,l)=>o|L(l),BigInt(0));return new e(n)}contains(t){return(this.value&L(t))!==BigInt(0)}insert(t){this.value|=L(t)}remove(t){this.value&=~L(t)}[Symbol.iterator](){let t=-1,n=new e(this.value);return{next(){for(;t<63;)if(t+=1,n.contains(t))return{value:t,done:!1};return{value:void 0,done:!0}}}}},G=W.bigint().transform(e=>new O(e));function L(e){return BigInt(1)<<BigInt(e)}var z;(p=>(p.RoomIdSchema=r.string(),p.RoomSchema=r.object({id:p.RoomIdSchema,customer:r.string(),user_data:x,peers:r.array(I)}),p.RoomUpdateSchema=r.discriminatedUnion("kind",[r.object({kind:r.literal("Joined"),room:p.RoomSchema,media_ids:r.array(S),own_peer_id:b}),r.object({kind:r.literal("Left"),reason:r.enum(["RoomClosing","ServerClosing","PeerKicked"])}),r.object({kind:r.literal("UserDataChanged"),user_data:r.optional(x)}),r.object({kind:r.literal("PeerJoined"),peer:I}),r.object({kind:r.literal("PeerLeft"),peer_id:b})]),p.RoomUpdatesSchema=r.object({updates:r.array(p.RoomUpdateSchema)}),p.RoomStatusSchema=r.enum(["Joining","Joined","Closed"]),p.RoomStatusChangedSchema=r.object({status:p.RoomStatusSchema,message:r.optional(r.string())})))(z||={});var ge;(a=>(a.ParametersSchema=r.record(r.string(),P),a.PeerProperties=r.object({user_data:x.optional(),tags:r.array(r.string()).optional(),audio_parameters:a.ParametersSchema.optional(),video_parameters:a.ParametersSchema.optional()}),a.PingSchema=r.object({Ping:r.object({id:r.number()})}),a.ChangeSelfSchema=r.object({ChangeSelf:a.PeerProperties.omit({tags:!0})}),a.SetAudioMaskSchema=r.object({SetAudioMask:r.object({peer_id:r.number(),mask:G})}),a.SendMessageSchema=r.object({SendMessage:r.object({peer_ids:r.number().array().default([]),message:x})}),a.CallSchema=a.PingSchema.or(a.ChangeSelfSchema).or(a.SetAudioMaskSchema).or(a.SendMessageSchema),a.PongSchema=r.object({Pong:r.object({id:r.number()})}),a.JoinedSchema=r.object({Joined:r.object({own_peer_id:r.number(),room_id:r.string(),customer:r.string()})}),a.LeftSchema=r.object({Left:r.object({reason:r.enum(["room_closing","server_closing","peer_kicked"])})}),a.PeerJoinedSchema=r.object({PeerJoined:a.PeerProperties.extend({peer_id:r.number(),user_id:r.string()})}),a.PeerLeftSchema=r.object({PeerLeft:r.object({peer_id:r.number()})}),a.PeerChangedSchema=r.object({PeerChanged:a.PeerProperties.extend({peer_id:r.number()})}),a.NewReconnectTokenSchema=r.object({NewReconnectToken:r.object({token:r.string()})}),a.MessageReceivedSchema=r.object({MessageReceived:r.object({sender_peer_id:r.number(),message:x})}),a.ErrorSchema=r.object({Error:r.object({message:x})}),a.EventSchema=a.PongSchema.or(a.JoinedSchema).or(a.LeftSchema).or(a.PeerJoinedSchema).or(a.PeerLeftSchema).or(a.PeerChangedSchema).or(a.NewReconnectTokenSchema).or(a.MessageReceivedSchema).or(a.ErrorSchema)))(ge||={});import{z as ye}from"zod";var E=ye.object({sender_peer_id:b,message:x});import*as s from"zod";var k=s.discriminatedUnion("kind",[s.object({kind:s.literal("Sdp"),type:s.enum(["Answer","Offer"]),sdp:s.string(),media_map:s.array(s.tuple([S,s.string()]))}),s.object({kind:s.literal("Trickle"),candidate:s.string(),spd_mid:s.optional(s.string()),spd_mline_index:s.optional(s.number()),username_fragment:s.optional(s.union([s.string(),s.null()]))}),s.object({kind:s.literal("TrickleFinished")})]);import{z as i}from"zod";function ot(e,t,n){let o=n[e];if(!o)return;let l=o.request.safeParse(t);return l.success?{name:e,request:l.data}:void 0}function it(e,t,n){return n[e].request.parse(t)}function at(e,t,n){let o=n[e].response.safeParse(t);return o.success?o.data:void 0}var st={Hello:{request:i.object({stream:i.literal("main")}),response:i.null()},JoinRoom:{request:i.object({token:i.string(),room_id:z.RoomIdSchema,user_data:x,position:A}),response:i.object({peer_id:b,stream_id:i.optional(i.number()),token:i.optional(i.string())})},WebRtcUpdate:{request:k,response:i.null()},RequestReconnectToken:{request:i.object({peer_id:i.optional(b)}),response:i.string()},Ping:{request:i.object({}),response:i.null()}},pt={Hello:{request:i.object({stream:i.literal("room"),token:i.string(),room_id:i.string(),user_data:x,position:A}),response:i.null()},UpdatePeer:{request:i.object({user_data:x}),response:i.null()},StartMedia:{request:i.object({media_id:S,properties:N}),response:i.null()},StopMedia:{request:i.object({media_id:S}),response:i.null()},PauseMedia:{request:i.object({media_id:S}),response:i.null()},ResumeMedia:{request:i.object({media_id:S}),response:i.null()},SetPeerPosition:{request:i.object({position:A}),response:i.null()},SendMessage:{request:i.object({target_peer_ids:i.optional(i.array(b)),message:x}),response:i.null()}};import{z as v}from"zod";function gt(e,t,n){let o=n[e];if(!o)return;let l=o.safeParse(t);return l.success?{name:e,properties:l.data}:void 0}var yt=v.object({name:v.literal("WebRtcUpdate"),properties:k}),xt={WebRtcUpdate:k},bt=v.union([v.object({name:v.literal("RoomStatusChanged"),properties:z.RoomStatusChangedSchema}),v.object({name:v.literal("RoomUpdated"),properties:z.RoomUpdatesSchema}),v.object({name:v.literal("PeerUpdated"),properties:B}),v.object({name:v.literal("MessageReceived"),properties:E})]),ht={RoomStatusChanged:z.RoomStatusChangedSchema,RoomUpdated:z.RoomUpdatesSchema,PeerUpdated:B,MessageReceived:E};function w(e,t){e||$(t)}function $(e){throw new Error(e)}function y(e){return{type:"Success",value:e}}function h(e){return{type:"Failure",reason:e}}function vt(e){return e.type==="Failure"&&$(e.reason),e.value}function D(e,t){return e.type==="Success"?e.value:t}function kt(e){try{let t=atob(e),n=Uint8Array.from(t,l=>l.codePointAt(0)),o=new TextDecoder("utf8");return y(o.decode(n))}catch(t){return h(String(t))}}function Rt(e){try{let t=atob(e.replace(/-/g,"+").replace(/_/g,"/")),n=Uint8Array.from(t,l=>l.codePointAt(0)),o=new TextDecoder("utf8");return y(o.decode(n))}catch(t){return h(String(t))}}function At(e){try{w(e!==void 0,"undefined cannot be converted to byte array"),w(e!==null,"null cannot be converted to byte array");let t=JSON.stringify(e),n=new TextEncoder;return y(n.encode(t))}catch(t){return h(String(t))}}function Lt(e){try{w(e.length>0,"empty byte array cannot be converted to value");let t=new TextDecoder().decode(e),n=JSON.parse(t);return y(n)}catch(t){return h(String(t))}}var xe=["VP8","VP9","AV1","H264"],H=class{constructor(t){this.codec=t}channels=0;clockRate=9e4;isValid(){return xe.includes(this.codec)}isSupported(){if(typeof RTCRtpReceiver>"u"||typeof RTCRtpReceiver.getCapabilities>"u")return null;let t=D(this.getMimeType(),"").toLowerCase(),n=new Set(D(this.getSdpFmtpLine(),"").split(";").map(o=>o.trim().toLowerCase()));return RTCRtpReceiver.getCapabilities("video")?.codecs?.find(o=>{let l=o.mimeType.toLowerCase(),f=new Set((o.sdpFmtpLine??"").split(";").map(p=>p.trim().toLowerCase()));if(t!==l||n.size!==f.size)return!1;for(let p of n)if(!f.has(p))return!1;return!0})??null}getPayloadType(){switch(this.codec){case"VP8":return y(96);case"VP9":return y(98);case"AV1":return y(41);case"H264":return y(102);default:return h("invalid video codec")}}getMimeType(){switch(this.codec){case"VP8":return y("video/VP8");case"VP9":return y("video/VP9");case"AV1":return y("video/AV1");case"H264":return y("video/H264");default:return h("invalid video codec")}}getSdpFmtpLine(){switch(this.codec){case"VP8":return y("");case"VP9":return y("profile-id=2");case"AV1":return y("level-idx=5;profile=0;tier=0");case"H264":return y("level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f");default:return h("invalid video codec")}}};function Ut(e,t){for(let n of e)if(t(n))return n}function _t(){return typeof AudioContext<"u"&&typeof Worker<"u"}function It(){return typeof SharedArrayBuffer<"u"}function be(){return/(apple)?webkit\/537\.36/i.test(globalThis.navigator.userAgent)}function Bt(){return/electron/i.test(globalThis.navigator.userAgent)}function Ot(){return/firefox|iceweasel|fxios/i.test(globalThis.navigator.userAgent)}function Et(){return be()?!1:/safari|applewebkit/i.test(globalThis.navigator.userAgent)}function Ft(e){return JSON.parse(JSON.stringify(e))}var Z=class e{constructor(t){this._Generators=t;this._Futures=t.map(e.addIndex)}_Futures;async next(){let[t,n]=await Promise.race(this._Futures);return this._Futures[n]=e.addIndex(this._Generators[n],n),t}static async addIndex(t,n){return[await t(),n]}};function qt(e,t){return e<=0?Promise.resolve(t):new Promise(n=>setTimeout(()=>n(t),e))}function Kt(e,t){return t.aborted?Promise.resolve("aborted"):new Promise(n=>{let o=()=>n("aborted");t.addEventListener("abort",o,{once:!0}),setTimeout(()=>{t.removeEventListener("abort",o),n(void 0)},e)})}function Wt(){return new Promise(e=>setTimeout(e,0))}var Y=class{_Tasks=[];_Running=!1;_Values;constructor(...t){this._Values=t}enqueue(t){return new Promise((n,o)=>{let l=async()=>{try{let f=await t(...this._Values);n(f)}catch(f){o(f)}};this._Tasks.push(l),this._Running||this.execute()})}async execute(){for(this._Running=!0;;){let t=this._Tasks.shift();if(t===void 0)break;await t()}this._Running=!1}};function Zt(e){let t=e.trim();e.indexOf("://")===-1&&(t=`https://${t}`);try{return y(new URL(t))}catch(n){return h(String(n))}}function Yt(e,t){let n=e.pathname;n.endsWith("/")===!1&&(n+="/");try{return y(new URL(n+t,e))}catch(o){return h(String(o))}}var he=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function Qt(){return crypto.randomUUID()}function er(e){return he.test(e)}function rr(e,t){return t in e}function nr(e){return typeof e=="function"}function or(e){return typeof e=="object"&&e===null}function ir(e){return typeof e=="number"}function ar(e){return typeof e=="object"}function sr(e){return typeof e=="string"}function pr(e){return typeof e>"u"}function cr(e){return e.type==="Failure"}function ur(e){return e.type==="Success"}var{Deno:X}=globalThis,Se=typeof X?.noColor=="boolean"?X.noColor:!1,ve=!Se;function F(e,t){return{open:`\x1B[${e.join(";")}m`,close:`\x1B[${t}m`,regexp:new RegExp(`\\x1b\\[${t}m`,"g")}}function V(e,t){return ve?`${t.open}${e.replace(t.regexp,t.open)}${t.close}`:e}function M(e){return V(e,F([0],0))}function J(e){return V(e,F([1],22))}function Q(e){return V(e,F([2],22))}var mr=new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TXZcf-nq-uy=><~]))"].join("|"),"g");var q=(g=>(g[g.Nothing=0]="Nothing",g[g.CRITICAL=1]="CRITICAL",g[g.ERROR=2]="ERROR",g[g.WARN=3]="WARN",g[g.INFO=4]="INFO",g[g.DEBUG=5]="DEBUG",g[g.Everything=6]="Everything",g))(q||{}),Ce=new Date,ne=(f=>(f[f.CRITICAL=1]="CRITICAL",f[f.ERROR=2]="ERROR",f[f.WARN=3]="WARN",f[f.INFO=4]="INFO",f[f.DEBUG=5]="DEBUG",f))(ne||{}),ke={1:"\u{1F4A5}",2:"\u{1F534}",3:"\u{1F7E1}",4:"\u{1F535}",5:"\u{1F7E3}"},Re={5:Q,4:M,3:M,2:J,1:J};function lr(e){for(let t of Object.keys(q))if(isNaN(Number(t))!==!1&&t.localeCompare(e,void 0,{sensitivity:"accent"})===0)return q[t]}function Pe({message:e}){return String(e)}function ee(e){return JSON.stringify({timestamp:e.date.toISOString(),level:ne[e.level],message:e.message,extra:e.extra})}function te(e){function t(p,g){return[Math.floor(p/g),p%g]}function n(){let p,g=e.date.valueOf()-Ce.valueOf();[g,p]=t(g,1e3);let[j,U]=t(g,60);return`${j.toString().padStart(4,"0")}:${U.toString().padStart(2,"0")}.${p.toString().padStart(4,"0")}`}function o(){return e.extra===void 0?"":"Deno"in globalThis?" "+Deno.inspect(e.extra,{compact:!1,colors:!0,trailingComma:!0}).trimStart():" "+JSON.stringify(e.extra)}let l=ke[e.level],f=e.logger.name!==void 0?`@${e.logger}`:"";return`${M(n())}${f} ${l} ${Re[e.level](String(e.message))}${o()}`}var Te={sparse:Pe,json:ee,pretty:te,default:"Deno"in globalThis&&Deno.stdout.isTerminal()?te:ee},K=class{#e;#t;filter;constructor(t=Te.default,n=6,o=console){this.filter=n,this.#e=t,this.#t=o}handle(t){let n=this.#e(t);switch(t.level){case 2:this.#t.error(n);break;case 3:this.#t.warn(n);break;case 4:this.#t.info(n);break;case 5:this.#t.debug(n);break}}},C=class{#e;sinks;filter;get name(){return this.#e}constructor(t,n=void 0,o=[new K]){this.#e=n,this.sinks=o,this.filter=t}log(t,n,o=void 0){if(this.filter<t)return;let l=re;for(let f of this.sinks)f.filter<t||(l===re&&(l={date:new Date,level:t,logger:this,message:typeof n=="function"?n():n,extra:o}),f.handle(l))}error=this.log.bind(this,2);warn=this.log.bind(this,3);info=this.log.bind(this,4);debug=this.log.bind(this,5)},R=new C(4),fr=C.prototype.log.bind(R,2),gr=C.prototype.log.bind(R,3),yr=C.prototype.log.bind(R,4),xr=C.prototype.log.bind(R,5),br=C.prototype.log.bind(R),re=Symbol();var Sr=-758.596,Ae;(t=>{let e;(p=>(p[p.InvalidPassword=-1]="InvalidPassword",p[p.Unknown=0]="Unknown",p[p.Unencrypted=1]="Unencrypted",p[p.Encrypted=2]="Encrypted"))(e=t.PeerCipherStatus||={})})(Ae||={});var vr={bytesSent:0,bytesReceived:0,packetsSent:0,packetsReceived:0,rtt:0,packetLoss:0},zr={packetsBuffered:0,packetsSeen:0,packetsProcessed:0,packetsTooEarly:0,packetsTooLate:0,packetsDropped:0,packetsInvalid:0,packetsRepeated:0,packetsLost:0},Cr={voiceActivity:{attackThreshold:.9,releaseThreshold:.8},volumeGate:{attackThreshold:-30,releaseThreshold:-40}},kr={echoCanceller:!0,highPassFilter:!1,noiseSuppression:"Moderate",transientSuppressor:!1,gainController:!0};export{kr as APM_DEFAULTS,Ae as Backend,x as ByteArraySchema,vr as CONNECTION_STATS_INITIAL,O as ChannelSet,G as ChannelSetSchema,K as ConsoleSink,Te as Formatter,R as GLOBAL_LOGGER,zr as JITTER_STATS_INITIAL,P as JsonSchema,q as LogFilter,ne as LogLevel,ke as LogSymbols,C as Logger,st as MainCommandsRpc,yt as MainNotificationSchema,xt as MainNotificationsRpc,le as MediaAudioPropertiesSchema,S as MediaIdSchema,N as MediaPropertiesSchema,_ as MediaSchema,fe as MediaVideoPropertiesSchema,Me as MessagePackRpcSchema,E as MessageReceivedSchema,Sr as MinDBFS,b as PeerIdSchema,A as PeerPositionSchema,I as PeerSchema,B as PeerUpdateSchema,pt as RoomCommandsRpc,bt as RoomNotificationSchema,ht as RoomNotificationsRpc,z as RoomV1,ge as RoomV2,Z as Selector,Y as Strand,de as TokenAudienceSchema,Ne as TokenClaimsSchema,me as TokenSubjectSchema,Cr as VAD_DEFAULTS,H as VideoCodec,k as WebRtcUpdateSchema,Kt as abortableSleep,w as assert,xr as debug,fr as error,Yt as extendUrl,$ as fail,h as failure,Ut as find,kt as fromBase64,Rt as fromBase64Url,Lt as fromBytes,Qt as generateUUID,yr as info,_t as isAudioCapable,be as isBlinkBrowser,Bt as isElectronBrowser,cr as isFailure,Ot as isFirefoxBrowser,nr as isFunction,or as isNull,ir as isNumber,ar as isObject,rr as isProperty,Et as isSafariBrowser,It as isSharedArrayBufferCapable,sr as isString,ur as isSuccess,pr as isUndefined,br as log,Wt as nextTick,Zt as normalizeUrl,T as oneOrMany,ot as parseCommand,gt as parseNotification,it as parseRequest,at as parseResponse,qt as sleep,y as success,At as toBytes,Ft as toRaw,lr as tryParseLogFilter,vt as unwrap,D as unwrapOr,er as validateUUID,gr as warn};
|
|
1
|
+
var G=-758.596,D;(t=>{let e;(s=>(s[s.InvalidPassword=-1]="InvalidPassword",s[s.Unknown=0]="Unknown",s[s.Unencrypted=1]="Unencrypted",s[s.Encrypted=2]="Encrypted"))(e=t.PeerCipherStatus||={})})(D||={});var W={bytesSent:0,bytesReceived:0,packetsSent:0,packetsReceived:0,rtt:0,packetLoss:0},H={packetsBuffered:0,packetsSeen:0,packetsProcessed:0,packetsTooEarly:0,packetsTooLate:0,packetsDropped:0,packetsInvalid:0,packetsRepeated:0,packetsLost:0},z={voiceActivity:{attackThreshold:.9,releaseThreshold:.8},volumeGate:{attackThreshold:-30,releaseThreshold:-40}},Z={echoCanceller:!0,highPassFilter:!1,noiseSuppression:"Moderate",transientSuppressor:!1,gainController:!0};function g(e,t){e||h(t)}function h(e){throw new Error(e)}function o(e){return{type:"Success",value:e}}function u(e){return{type:"Failure",reason:e}}function Y(e){return e.type==="Failure"&&h(e.reason),e.value}function b(e,t){return e.type==="Success"?e.value:t}function Q(e){try{let t=atob(e),r=Uint8Array.from(t,a=>a.codePointAt(0)),n=new TextDecoder("utf8");return o(n.decode(r))}catch(t){return u(String(t))}}function ee(e){try{let t=atob(e.replace(/-/g,"+").replace(/_/g,"/")),r=Uint8Array.from(t,a=>a.codePointAt(0)),n=new TextDecoder("utf8");return o(n.decode(r))}catch(t){return u(String(t))}}function ne(e){try{g(e!==void 0,"undefined cannot be converted to byte array"),g(e!==null,"null cannot be converted to byte array");let t=JSON.stringify(e),r=new TextEncoder;return o(r.encode(t))}catch(t){return u(String(t))}}function oe(e){try{g(e.length>0,"empty byte array cannot be converted to value");let t=new TextDecoder().decode(e),r=JSON.parse(t);return o(r)}catch(t){return u(String(t))}}var B=["VP8","VP9","AV1","H264"],L=class{constructor(t){this.codec=t}channels=0;clockRate=9e4;isValid(){return B.includes(this.codec)}isSupported(){if(typeof RTCRtpReceiver>"u"||typeof RTCRtpReceiver.getCapabilities>"u")return null;let t=b(this.getMimeType(),"").toLowerCase(),r=new Set(b(this.getSdpFmtpLine(),"").split(";").map(n=>n.trim().toLowerCase()));return RTCRtpReceiver.getCapabilities("video")?.codecs?.find(n=>{let a=n.mimeType.toLowerCase(),i=new Set((n.sdpFmtpLine??"").split(";").map(s=>s.trim().toLowerCase()));if(t!==a||r.size!==i.size)return!1;for(let s of r)if(!i.has(s))return!1;return!0})??null}getPayloadType(){switch(this.codec){case"VP8":return o(96);case"VP9":return o(98);case"AV1":return o(41);case"H264":return o(102);default:return u("invalid video codec")}}getMimeType(){switch(this.codec){case"VP8":return o("video/VP8");case"VP9":return o("video/VP9");case"AV1":return o("video/AV1");case"H264":return o("video/H264");default:return u("invalid video codec")}}getSdpFmtpLine(){switch(this.codec){case"VP8":return o("");case"VP9":return o("profile-id=2");case"AV1":return o("level-idx=5;profile=0;tier=0");case"H264":return o("level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f");default:return u("invalid video codec")}}};function ue(e,t){for(let r of e)if(t(r))return r}function le(){return typeof AudioContext<"u"&&typeof Worker<"u"}function pe(){return typeof SharedArrayBuffer<"u"}function I(){return/(apple)?webkit\/537\.36/i.test(globalThis.navigator.userAgent)}function de(){return/electron/i.test(globalThis.navigator.userAgent)}function ge(){return/firefox|iceweasel|fxios/i.test(globalThis.navigator.userAgent)}function fe(){return I()?!1:/safari|applewebkit/i.test(globalThis.navigator.userAgent)}function be(e){return JSON.parse(JSON.stringify(e))}var R=class e{constructor(t){this._Generators=t;this._Futures=t.map(e.addIndex)}_Futures;async next(){let[t,r]=await Promise.race(this._Futures);return this._Futures[r]=e.addIndex(this._Generators[r],r),t}static async addIndex(t,r){return[await t(),r]}};function ve(e,t){return e<=0?Promise.resolve(t):new Promise(r=>setTimeout(()=>r(t),e))}function he(e,t){return t.aborted?Promise.resolve("aborted"):new Promise(r=>{let n=()=>r("aborted");t.addEventListener("abort",n,{once:!0}),setTimeout(()=>{t.removeEventListener("abort",n),r(void 0)},e)})}function Le(){return new Promise(e=>setTimeout(e,0))}var T=class{_Tasks=[];_Running=!1;_Values;constructor(...t){this._Values=t}enqueue(t){return new Promise((r,n)=>{let a=async()=>{try{let i=await t(...this._Values);r(i)}catch(i){n(i)}};this._Tasks.push(a),this._Running||this.execute()})}async execute(){for(this._Running=!0;;){let t=this._Tasks.shift();if(t===void 0)break;await t()}this._Running=!1}};function Ce(e){let t=e.trim();e.indexOf("://")===-1&&(t=`https://${t}`);try{return o(new URL(t))}catch(r){return u(String(r))}}function Se(e,t){let r=e.pathname;r.endsWith("/")===!1&&(r+="/");try{return o(new URL(r+t,e))}catch(n){return u(String(n))}}var E=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function Ae(){return crypto.randomUUID()}function we(e){return E.test(e)}function Oe(e,t){return t in e}function De(e){return typeof e=="function"}function Be(e){return typeof e=="object"&&e===null}function Ie(e){return typeof e=="number"}function Ee(e){return typeof e=="object"}function Fe(e){return typeof e=="string"}function Ue(e){return typeof e>"u"}function Ne(e){return e.type==="Failure"}function Me(e){return e.type==="Success"}var{Deno:k}=globalThis,F=typeof k?.noColor=="boolean"?k.noColor:!1,U=!F;function y(e,t){return{open:`\x1B[${e.join(";")}m`,close:`\x1B[${t}m`,regexp:new RegExp(`\\x1b\\[${t}m`,"g")}}function x(e,t){return U?`${t.open}${e.replace(t.regexp,t.open)}${t.close}`:e}function f(e){return x(e,y([0],0))}function v(e){return x(e,y([1],22))}function C(e){return x(e,y([2],22))}var _e=new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TXZcf-nq-uy=><~]))"].join("|"),"g");var M=new Date,p=(i=>(i[i.CRITICAL=0]="CRITICAL",i[i.ERROR=1]="ERROR",i[i.WARN=2]="WARN",i[i.INFO=3]="INFO",i[i.DEBUG=4]="DEBUG",i))(p||{}),w={0:"\u{1F4A5}",1:"\u{1F534}",2:"\u{1F7E1}",3:"\u{1F535}",4:"\u{1F7E3}"},j={4:C,3:f,2:f,1:v,0:v};function $e(e){for(let t of Object.keys(p))if(isNaN(Number(t))!==!1&&t.localeCompare(e,void 0,{sensitivity:"accent"})===0)return p[t]}function _({message:e}){return String(e)}function S(e){return JSON.stringify({timestamp:e.date.toISOString(),level:p[e.level],message:e.message,extra:e.extra})}function P(e){function t(s,l){return[Math.floor(s/l),s%l]}function r(){let s,l=e.date.valueOf()-M.valueOf();[l,s]=t(l,1e3);let[V,O]=t(l,60);return`${V.toString().padStart(4,"0")}:${O.toString().padStart(2,"0")}.${s.toString().padStart(4,"0")}`}function n(){return e.extra===void 0?"":"Deno"in globalThis?" "+Deno.inspect(e.extra,{compact:!1,colors:!0,trailingComma:!0}).trimStart():" "+JSON.stringify(e.extra)}let a=w[e.level],i=e.logger.name!==void 0?`@${e.logger}`:"";return`${f(r())}${i} ${a} ${j[e.level](String(e.message))}${n()}`}function $(e){let t=`[${e.date.toISOString()}]`,r=`[${p[e.level]}]`,n=e.logger.name!==void 0?`[${e.logger.name}] `:"",a=w[e.level];return`${t} ${a} ${r.padEnd(7," ")} ${n}${e.message}`}var J={sparse:_,json:S,pretty:P,structured:$,default:"Deno"in globalThis&&Deno.stdout.isTerminal()?P:S},m=class{formatter;consoleObject;filter;constructor(t=J.default,r=4,n=console){this.filter=r,this.formatter=t,this.consoleObject=n}handle(t){let r=this.formatter(t);switch(t.level){case 1:this.consoleObject.error(r);break;case 2:this.consoleObject.warn(r);break;case 3:this.consoleObject.info(r);break;case 4:this.consoleObject.debug(r);break}}},A=class extends m{handle(t){let r=this.formatter(t),n=t.extra!==void 0?[r,t.extra]:[r];switch(t.level){case 0:case 1:this.consoleObject.error(...n);break;case 2:this.consoleObject.warn(...n);break;case 3:this.consoleObject.info(...n);break;case 4:this.consoleObject.debug(...n);break}}},c=class{#e;sinks;filter;parent;get name(){return this.#e}constructor(t,r=void 0,n=[],a=void 0){this.#e=r,this.sinks=n,this.filter=t,this.parent=a}log(t,r,n=void 0){let i={date:new Date,level:t,logger:this,message:r,extra:n};this.filter<t||this.insert(i)}insert(t){if(!(this.filter<t.level)){for(let r of this.sinks)r.filter>=t.level&&r.handle(t);this.parent!==void 0&&this.parent.insert(t)}}error=this.log.bind(this,1);warn=this.log.bind(this,2);info=this.log.bind(this,3);debug=this.log.bind(this,4)},d=new c(3,void 0,[new m]),Je=c.prototype.log.bind(d,1),Ge=c.prototype.log.bind(d,2),We=c.prototype.log.bind(d,3),He=c.prototype.log.bind(d,4),ze=c.prototype.log.bind(d);export{Z as APM_DEFAULTS,D as Backend,W as CONNECTION_STATS_INITIAL,m as ConsoleSink,J as Formatter,d as GLOBAL_LOGGER,A as InteractiveConsoleSink,H as JITTER_STATS_INITIAL,p as LogLevel,w as LogSymbols,c as Logger,G as MinDBFS,R as Selector,T as Strand,z as VAD_DEFAULTS,L as VideoCodec,he as abortableSleep,g as assert,He as debug,Je as error,Se as extendUrl,h as fail,u as failure,ue as find,Q as fromBase64,ee as fromBase64Url,oe as fromBytes,Ae as generateUUID,We as info,le as isAudioCapable,I as isBlinkBrowser,de as isElectronBrowser,Ne as isFailure,ge as isFirefoxBrowser,De as isFunction,Be as isNull,Ie as isNumber,Ee as isObject,Oe as isProperty,fe as isSafariBrowser,pe as isSharedArrayBufferCapable,Fe as isString,Me as isSuccess,Ue as isUndefined,ze as log,Le as nextTick,Ce as normalizeUrl,ve as sleep,o as success,ne as toBytes,be as toRaw,$e as tryParseLogLevel,Y as unwrap,b as unwrapOr,we as validateUUID,Ge as warn};
|
package/mod.d.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './schema/token.ts';
|
|
3
|
-
export * from './schema/room.ts';
|
|
4
|
-
export * from './schema/peer.ts';
|
|
5
|
-
export * from './schema/media.ts';
|
|
6
|
-
export * from './schema/message.ts';
|
|
7
|
-
export * from './schema/webrtc.ts';
|
|
8
|
-
export * from './schema/channels.ts';
|
|
9
|
-
export * from './rpc/commands.ts';
|
|
10
|
-
export * from './rpc/notifications.ts';
|
|
1
|
+
export * from './plugin/api.ts';
|
|
11
2
|
export * from './utility/base64.ts';
|
|
12
3
|
export * from './utility/bytearray.ts';
|
|
13
4
|
export * from './utility/codec.ts';
|
|
@@ -22,4 +13,3 @@ export * from './utility/url.ts';
|
|
|
22
13
|
export * from './utility/uuid.ts';
|
|
23
14
|
export * from './utility/validation.ts';
|
|
24
15
|
export * from './utility/log.ts';
|
|
25
|
-
export * from './plugin/api.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4players/odin-common",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0",
|
|
4
4
|
"description": "A collection of commonly used type definitions and utility functions across ODIN web projects",
|
|
5
5
|
"author": "Josho Bleicker <josho.bleicker@4players.io> (https://www.4players.io)",
|
|
6
6
|
"homepage": "https://www.4players.io",
|
package/utility/bytearray.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ByteArray, JsonValue } from '../
|
|
1
|
+
import type { ByteArray, JsonValue } from '../api/serialization.ts';
|
|
2
2
|
import { type Result } from './result.ts';
|
|
3
3
|
export declare function toBytes(value: JsonValue): Result<ByteArray>;
|
|
4
4
|
export declare function fromBytes(bytes: ByteArray): Result<JsonValue>;
|
package/utility/json.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { JsonValue } from '../
|
|
1
|
+
import type { JsonValue } from '../api/serialization.ts';
|
|
2
2
|
export declare function toRaw<T extends JsonValue>(value: T): JsonValue;
|
package/utility/log.d.ts
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
export declare enum LogFilter {
|
|
2
|
-
Nothing = 0,
|
|
3
|
-
CRITICAL = 1,
|
|
4
|
-
ERROR = 2,
|
|
5
|
-
WARN = 3,
|
|
6
|
-
INFO = 4,
|
|
7
|
-
DEBUG = 5,
|
|
8
|
-
Everything = 6
|
|
9
|
-
}
|
|
10
1
|
export declare enum LogLevel {
|
|
11
|
-
CRITICAL =
|
|
12
|
-
ERROR =
|
|
13
|
-
WARN =
|
|
14
|
-
INFO =
|
|
15
|
-
DEBUG =
|
|
2
|
+
CRITICAL = 0,
|
|
3
|
+
ERROR = 1,
|
|
4
|
+
WARN = 2,
|
|
5
|
+
INFO = 3,
|
|
6
|
+
DEBUG = 4
|
|
16
7
|
}
|
|
17
8
|
export declare const LogSymbols: {
|
|
18
9
|
[Level in LogLevel]: string;
|
|
19
10
|
};
|
|
20
|
-
export declare function
|
|
11
|
+
export declare function tryParseLogLevel(text: string): LogLevel | undefined;
|
|
21
12
|
export interface LogSink {
|
|
22
|
-
filter:
|
|
13
|
+
filter: LogLevel;
|
|
23
14
|
handle(record: LogRecord): void;
|
|
24
15
|
}
|
|
25
16
|
export type ConsoleObject = Pick<typeof console, 'error' | 'warn' | 'info' | 'debug'>;
|
|
@@ -27,42 +18,49 @@ export type LogFormatter = (record: LogRecord) => string;
|
|
|
27
18
|
declare function sparseFormat({ message }: LogRecord): string;
|
|
28
19
|
declare function jsonFormat(record: LogRecord): string;
|
|
29
20
|
declare function prettyFormat(record: LogRecord): string;
|
|
21
|
+
declare function structuredFormat(record: LogRecord): string;
|
|
30
22
|
export declare const Formatter: {
|
|
31
23
|
sparse: typeof sparseFormat;
|
|
32
24
|
json: typeof jsonFormat;
|
|
33
25
|
pretty: typeof prettyFormat;
|
|
26
|
+
structured: typeof structuredFormat;
|
|
34
27
|
default: typeof jsonFormat;
|
|
35
28
|
};
|
|
36
29
|
export declare class ConsoleSink implements LogSink {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
protected formatter: LogFormatter;
|
|
31
|
+
protected consoleObject: ConsoleObject;
|
|
32
|
+
filter: LogLevel;
|
|
33
|
+
constructor(formatter?: LogFormatter, filter?: LogLevel, consoleObject?: ConsoleObject);
|
|
34
|
+
handle(record: LogRecord): void;
|
|
35
|
+
}
|
|
36
|
+
export declare class InteractiveConsoleSink extends ConsoleSink {
|
|
40
37
|
handle(record: LogRecord): void;
|
|
41
38
|
}
|
|
42
39
|
export declare class Logger {
|
|
43
40
|
#private;
|
|
44
41
|
sinks: LogSink[];
|
|
45
|
-
filter:
|
|
42
|
+
filter: LogLevel;
|
|
43
|
+
parent: Logger | undefined;
|
|
46
44
|
get name(): string | undefined;
|
|
47
|
-
constructor(filter:
|
|
48
|
-
log(level: LogLevel, message:
|
|
49
|
-
|
|
50
|
-
readonly
|
|
51
|
-
readonly
|
|
52
|
-
readonly
|
|
45
|
+
constructor(filter: LogLevel, name?: string | undefined, sinks?: LogSink[], parent?: Logger | undefined);
|
|
46
|
+
log(level: LogLevel, message: string, extra?: Record<string, unknown> | undefined): void;
|
|
47
|
+
insert(record: LogRecord): void;
|
|
48
|
+
readonly error: (message: string, extra?: Record<string, unknown> | undefined) => void;
|
|
49
|
+
readonly warn: (message: string, extra?: Record<string, unknown> | undefined) => void;
|
|
50
|
+
readonly info: (message: string, extra?: Record<string, unknown> | undefined) => void;
|
|
51
|
+
readonly debug: (message: string, extra?: Record<string, unknown> | undefined) => void;
|
|
53
52
|
}
|
|
54
53
|
export declare const GLOBAL_LOGGER: Logger;
|
|
55
|
-
export
|
|
56
|
-
export declare const
|
|
57
|
-
export declare const
|
|
58
|
-
export declare const
|
|
59
|
-
export declare const
|
|
60
|
-
export declare const log: (level: LogLevel, message: LogMessage, extra?: Record<string, unknown> | undefined) => void;
|
|
54
|
+
export declare const error: (message: string, extra?: Record<string, unknown> | undefined) => void;
|
|
55
|
+
export declare const warn: (message: string, extra?: Record<string, unknown> | undefined) => void;
|
|
56
|
+
export declare const info: (message: string, extra?: Record<string, unknown> | undefined) => void;
|
|
57
|
+
export declare const debug: (message: string, extra?: Record<string, unknown> | undefined) => void;
|
|
58
|
+
export declare const log: (level: LogLevel, message: string, extra?: Record<string, unknown> | undefined) => void;
|
|
61
59
|
export interface LogRecord {
|
|
62
60
|
readonly date: Date;
|
|
63
61
|
readonly level: LogLevel;
|
|
64
62
|
readonly logger: Logger;
|
|
65
|
-
readonly message:
|
|
63
|
+
readonly message: string;
|
|
66
64
|
readonly extra: Record<string, unknown> | undefined;
|
|
67
65
|
}
|
|
68
66
|
export {};
|
package/rpc/commands.d.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { type RpcSchema } from '../schema/serialization.ts';
|
|
3
|
-
export type Infer<T extends RpcSchema> = z.output<T>;
|
|
4
|
-
export type CommandSchema = {
|
|
5
|
-
request: RpcSchema;
|
|
6
|
-
response: RpcSchema;
|
|
7
|
-
};
|
|
8
|
-
export type Commands = Record<string, CommandSchema>;
|
|
9
|
-
export type CommandRequest<C extends Commands, K extends keyof C> = z.infer<C[K]['request']>;
|
|
10
|
-
export type CommandResponse<C extends Commands, K extends keyof C> = z.infer<C[K]['response']>;
|
|
11
|
-
export type ParsedCommand<C extends Commands, K extends keyof C = keyof C> = {
|
|
12
|
-
[Name in K]: {
|
|
13
|
-
name: Name;
|
|
14
|
-
request: z.infer<C[Name]['request']>;
|
|
15
|
-
};
|
|
16
|
-
}[K];
|
|
17
|
-
export declare function parseCommand<C extends Commands, K extends keyof C>(name: K, request: unknown, schema: C): ParsedCommand<C, K> | undefined;
|
|
18
|
-
export declare function parseRequest<C extends Commands, K extends keyof C>(name: K, request: unknown, schema: C): CommandRequest<C, K>;
|
|
19
|
-
export declare function parseResponse<C extends Commands, K extends keyof C>(name: K, response: unknown, schema: C): CommandResponse<C, K> | undefined;
|
|
20
|
-
export declare const MainCommandsRpc: {
|
|
21
|
-
Hello: {
|
|
22
|
-
request: z.ZodObject<{
|
|
23
|
-
stream: z.ZodLiteral<"main">;
|
|
24
|
-
}, z.core.$strip>;
|
|
25
|
-
response: z.ZodNull;
|
|
26
|
-
};
|
|
27
|
-
JoinRoom: {
|
|
28
|
-
request: z.ZodObject<{
|
|
29
|
-
token: z.ZodString;
|
|
30
|
-
room_id: z.ZodString;
|
|
31
|
-
user_data: z.ZodCustom<Uint8Array, Uint8Array>;
|
|
32
|
-
position: z.ZodUnion<readonly [z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>]>;
|
|
33
|
-
}, z.core.$strip>;
|
|
34
|
-
response: z.ZodObject<{
|
|
35
|
-
peer_id: z.ZodNumber;
|
|
36
|
-
stream_id: z.ZodOptional<z.ZodNumber>;
|
|
37
|
-
token: z.ZodOptional<z.ZodString>;
|
|
38
|
-
}, z.core.$strip>;
|
|
39
|
-
};
|
|
40
|
-
WebRtcUpdate: {
|
|
41
|
-
request: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
42
|
-
kind: z.ZodLiteral<"Sdp">;
|
|
43
|
-
type: z.ZodEnum<{
|
|
44
|
-
Answer: "Answer";
|
|
45
|
-
Offer: "Offer";
|
|
46
|
-
}>;
|
|
47
|
-
sdp: z.ZodString;
|
|
48
|
-
media_map: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodString], null>>;
|
|
49
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
50
|
-
kind: z.ZodLiteral<"Trickle">;
|
|
51
|
-
candidate: z.ZodString;
|
|
52
|
-
spd_mid: z.ZodOptional<z.ZodString>;
|
|
53
|
-
spd_mline_index: z.ZodOptional<z.ZodNumber>;
|
|
54
|
-
username_fragment: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
55
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
56
|
-
kind: z.ZodLiteral<"TrickleFinished">;
|
|
57
|
-
}, z.core.$strip>], "kind">;
|
|
58
|
-
response: z.ZodNull;
|
|
59
|
-
};
|
|
60
|
-
RequestReconnectToken: {
|
|
61
|
-
request: z.ZodObject<{
|
|
62
|
-
peer_id: z.ZodOptional<z.ZodNumber>;
|
|
63
|
-
}, z.core.$strip>;
|
|
64
|
-
response: z.ZodString;
|
|
65
|
-
};
|
|
66
|
-
Ping: {
|
|
67
|
-
request: z.ZodObject<{}, z.core.$strip>;
|
|
68
|
-
response: z.ZodNull;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
export type MainCommands = typeof MainCommandsRpc;
|
|
72
|
-
export declare const RoomCommandsRpc: {
|
|
73
|
-
Hello: {
|
|
74
|
-
request: z.ZodObject<{
|
|
75
|
-
stream: z.ZodLiteral<"room">;
|
|
76
|
-
token: z.ZodString;
|
|
77
|
-
room_id: z.ZodString;
|
|
78
|
-
user_data: z.ZodCustom<Uint8Array, Uint8Array>;
|
|
79
|
-
position: z.ZodUnion<readonly [z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>]>;
|
|
80
|
-
}, z.core.$strip>;
|
|
81
|
-
response: z.ZodNull;
|
|
82
|
-
};
|
|
83
|
-
UpdatePeer: {
|
|
84
|
-
request: z.ZodObject<{
|
|
85
|
-
user_data: z.ZodCustom<Uint8Array, Uint8Array>;
|
|
86
|
-
}, z.core.$strip>;
|
|
87
|
-
response: z.ZodNull;
|
|
88
|
-
};
|
|
89
|
-
StartMedia: {
|
|
90
|
-
request: z.ZodObject<{
|
|
91
|
-
media_id: z.ZodNumber;
|
|
92
|
-
properties: z.ZodUnion<readonly [z.ZodObject<{
|
|
93
|
-
kind: z.ZodOptional<z.ZodLiteral<"audio">>;
|
|
94
|
-
uid: z.ZodOptional<z.ZodString>;
|
|
95
|
-
customType: z.ZodOptional<z.ZodString>;
|
|
96
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
97
|
-
kind: z.ZodOptional<z.ZodLiteral<"video">>;
|
|
98
|
-
codec: z.ZodOptional<z.ZodString>;
|
|
99
|
-
uid: z.ZodOptional<z.ZodString>;
|
|
100
|
-
customType: z.ZodOptional<z.ZodString>;
|
|
101
|
-
id: z.ZodOptional<z.ZodString>;
|
|
102
|
-
}, z.core.$strip>]>;
|
|
103
|
-
}, z.core.$strip>;
|
|
104
|
-
response: z.ZodNull;
|
|
105
|
-
};
|
|
106
|
-
StopMedia: {
|
|
107
|
-
request: z.ZodObject<{
|
|
108
|
-
media_id: z.ZodNumber;
|
|
109
|
-
}, z.core.$strip>;
|
|
110
|
-
response: z.ZodNull;
|
|
111
|
-
};
|
|
112
|
-
PauseMedia: {
|
|
113
|
-
request: z.ZodObject<{
|
|
114
|
-
media_id: z.ZodNumber;
|
|
115
|
-
}, z.core.$strip>;
|
|
116
|
-
response: z.ZodNull;
|
|
117
|
-
};
|
|
118
|
-
ResumeMedia: {
|
|
119
|
-
request: z.ZodObject<{
|
|
120
|
-
media_id: z.ZodNumber;
|
|
121
|
-
}, z.core.$strip>;
|
|
122
|
-
response: z.ZodNull;
|
|
123
|
-
};
|
|
124
|
-
SetPeerPosition: {
|
|
125
|
-
request: z.ZodObject<{
|
|
126
|
-
position: z.ZodUnion<readonly [z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>]>;
|
|
127
|
-
}, z.core.$strip>;
|
|
128
|
-
response: z.ZodNull;
|
|
129
|
-
};
|
|
130
|
-
SendMessage: {
|
|
131
|
-
request: z.ZodObject<{
|
|
132
|
-
target_peer_ids: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
133
|
-
message: z.ZodCustom<Uint8Array, Uint8Array>;
|
|
134
|
-
}, z.core.$strip>;
|
|
135
|
-
response: z.ZodNull;
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
export type RoomCommands = typeof RoomCommandsRpc;
|