@4players/odin-plugin-web 1.0.0-alpha.8 → 1.0.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.
@@ -1,299 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { RpcConnection } from './rpcConnection';
11
- import { Token } from './token';
12
- import { Selector, failure, sleep, success, RoomCommandsRpc, } from '@4players/odin-common';
13
- import * as z from 'zod';
14
- import { ConnectTimeout, MinTokenLifetime, MinTokenRefreshInterval, } from './config';
15
- export class RoomConnection {
16
- get token() {
17
- return this._Token;
18
- }
19
- get userData() {
20
- return this._UserData;
21
- }
22
- get position() {
23
- return this._Position;
24
- }
25
- get closed() {
26
- return this._Close.signal.aborted;
27
- }
28
- get mainConnection() {
29
- return this._MainConnection;
30
- }
31
- constructor(connectionPool, onEvent, gateway, token, roomId, userData, position) {
32
- this.connectionPool = connectionPool;
33
- this.onEvent = onEvent;
34
- this.gateway = gateway;
35
- this.roomId = roomId;
36
- this._Close = new AbortController();
37
- this._LastTokenRenew = performance.now();
38
- this._Closed = new Promise((accept) => this._Close.signal.addEventListener('abort', () => accept('closed'), {
39
- once: true,
40
- }));
41
- this._Token = token;
42
- this._UserData = userData;
43
- this._Position = position;
44
- this._Main().then(({ reason }) => console.debug(`room closed; ${reason}`));
45
- }
46
- request(name, properties) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- if (this._RoomConnection === undefined) {
49
- return failure('currently not connected');
50
- }
51
- const response = yield this._RoomConnection.request(name, properties);
52
- if (response !== 'closed' && response.type === 'Success') {
53
- this._HandleRequests(name, properties, response.value);
54
- }
55
- return response;
56
- });
57
- }
58
- typedRequest(name, properties) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const schema = RoomCommandsRpc[name];
61
- const response = yield this.request(name, properties);
62
- if (response === 'closed' || response.type === 'Failure')
63
- return response;
64
- const parsed = schema.response.safeParse(response.value);
65
- if (parsed.success)
66
- return success(parsed.data);
67
- else {
68
- return failure(`received invalid response from ${name}; ${parsed.error}`);
69
- }
70
- });
71
- }
72
- close() {
73
- this._Close.abort();
74
- }
75
- get renewTokenIn() {
76
- const earliest = this._LastTokenRenew - performance.now() + MinTokenRefreshInterval;
77
- const latest = this._Token.timeLeft - MinTokenLifetime;
78
- return Math.max(earliest, latest);
79
- }
80
- _Main() {
81
- var _a;
82
- return __awaiter(this, void 0, void 0, function* () {
83
- let closeReason = 'unable to establish connection';
84
- /// as long as we are asked to continue
85
- while (this._Close.signal.aborted === false) {
86
- const result = yield this._ConnectToServer();
87
- if (result.type === 'Failure') {
88
- closeReason = result.reason;
89
- break;
90
- }
91
- (_a = this._RoomConnection) === null || _a === void 0 ? void 0 : _a.close();
92
- this._RoomConnection = undefined;
93
- this._MainConnection = undefined;
94
- // can the token be used to request a better token from a gateway?
95
- if (this.gateway !== undefined && this._Token.hasAudience('gateway')) {
96
- this._ChangeStatus('Joining', `requesting new token from ${this.gateway}`);
97
- const newToken = yield contactGateway(this.gateway, this._Token, this._Close.signal);
98
- if (newToken.type === 'Success') {
99
- if (newToken.value !== 'rejected') {
100
- // we got a better token, lets retry.
101
- this._Token = newToken.value;
102
- continue;
103
- }
104
- else {
105
- closeReason = 'invalid or expired token';
106
- break;
107
- }
108
- }
109
- }
110
- // we failed to get a connection, should we try again?
111
- if (this._Token.timeLeft <= 0) {
112
- closeReason = 'unable to use expired token';
113
- break;
114
- }
115
- // slow retries down
116
- yield sleep(1000);
117
- }
118
- this._ChangeStatus('Closed', this._Close.signal.aborted ? 'user requested' : closeReason);
119
- this.close();
120
- return failure(closeReason);
121
- });
122
- }
123
- _ConnectToServer() {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- if (!this._Token.hasAudience('sfu') || this._Token.address === undefined) {
126
- return success('continue');
127
- }
128
- this._ChangeStatus('Joining', `connecting to ${this._Token.address}`);
129
- // are we already connected to the server?
130
- if (this._MainConnection === undefined ||
131
- this._MainConnection.closed ||
132
- this._MainConnection.url !== this._Token.address) {
133
- // no? release the not fitting connection
134
- if (this._MainConnection) {
135
- this.connectionPool.releaseConnection(this._MainConnection);
136
- }
137
- // connect to the right server
138
- const mainConnection = yield this.connectionPool.acquireConnection(this._Token.address, this._Close.signal);
139
- if (mainConnection === 'closed')
140
- return failure('connection pool closed'); // connection pool is closed
141
- if (mainConnection.type === 'Failure') {
142
- this._ChangeStatus('Joining', `connection failed; ${mainConnection.reason}`);
143
- return success('continue');
144
- }
145
- this._MainConnection = mainConnection.value;
146
- }
147
- // join room
148
- const result = yield Promise.race([
149
- Promise.all([
150
- this._MainConnection.joinRoom(this._Token, this.roomId, this.userData, this.position),
151
- ]),
152
- sleep(ConnectTimeout, 'timeout'),
153
- this._Closed,
154
- ]);
155
- if (result === 'closed')
156
- return failure('room connection closed'); // room connection was closed
157
- if (result !== 'timeout') {
158
- const [websocket] = result;
159
- if (websocket === 'closed')
160
- return success('continue'); // connection was lost, before joinRoom finished
161
- if (websocket.type === 'Failure') {
162
- // join was rejected by the server
163
- return failure(`unable to join room; ${websocket.reason}`);
164
- }
165
- // room connection is open, make it available
166
- this._RoomConnection = new RpcConnection(websocket.value);
167
- this._ChangeStatus('Joined', `joined room ${this.roomId} on ${websocket.value.url}`);
168
- // TODO(sven): handle this
169
- // await this._MainConnection.webRtcReady()
170
- // process room events
171
- yield this._HandleConnection(this._MainConnection, websocket.value);
172
- }
173
- // try to reconnect
174
- return success('continue');
175
- });
176
- }
177
- _ChangeStatus(status, message) {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- const properties = {
180
- status,
181
- message,
182
- };
183
- this.onEvent('RoomStatusChanged', properties);
184
- });
185
- }
186
- _HandleConnection(main, webSocket) {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- if (this._RoomConnection === undefined)
189
- return;
190
- const selector = new Selector([
191
- () => sleep(this.renewTokenIn, 'renewToken'),
192
- () => sleep(500, 'tick'),
193
- () => __awaiter(this, void 0, void 0, function* () { var _a; return yield ((_a = this._RoomConnection) === null || _a === void 0 ? void 0 : _a.recv()); }),
194
- () => this._Closed,
195
- () => main.closePromise,
196
- ]);
197
- while (true) {
198
- const value = yield selector.next();
199
- switch (value) {
200
- case undefined:
201
- case 'closed':
202
- webSocket.close();
203
- return;
204
- case 'renewToken':
205
- this._RenewToken(main, webSocket);
206
- break;
207
- case 'tick':
208
- break;
209
- default:
210
- this._HandleEvent(value);
211
- break;
212
- }
213
- }
214
- });
215
- }
216
- _HandleEvent(event) {
217
- this.onEvent(event.name, event.properties);
218
- }
219
- _HandleRequests(name, properties, response) {
220
- switch (name) {
221
- case 'SetPeerPosition':
222
- // eslint-disable-next-line no-case-declarations
223
- const setPeerPosition = RoomCommandsRpc.SetPeerPosition.request.safeParse(properties);
224
- if (setPeerPosition.success) {
225
- const value = setPeerPosition.data.position;
226
- this._Position = value.length === 2 ? [value[0], value[1], 0] : value;
227
- }
228
- else {
229
- console.warn('unable to process SetPeerPosition command');
230
- }
231
- break;
232
- case 'UpdatePeer':
233
- // eslint-disable-next-line no-case-declarations
234
- const updatePeer = RoomCommandsRpc.UpdatePeer.request.safeParse(properties);
235
- if (updatePeer.success) {
236
- this._UserData = updatePeer.data.user_data;
237
- }
238
- else {
239
- console.warn('unable to process UpdatePeer command');
240
- }
241
- break;
242
- }
243
- }
244
- _RenewToken(main, webSocket) {
245
- return __awaiter(this, void 0, void 0, function* () {
246
- this._LastTokenRenew = performance.now();
247
- if (this.token.timeLeft > MinTokenLifetime)
248
- return;
249
- const response = yield main.getReconnectToken(webSocket);
250
- if (response.type === 'Success') {
251
- if (response.value.timeLeft > this._Token.timeLeft) {
252
- this._Token = response.value;
253
- }
254
- }
255
- else {
256
- console.warn(`${main.url} rejected reconnect token request; ${response.reason}`);
257
- }
258
- });
259
- }
260
- }
261
- function contactGateway(gateway, token, signal) {
262
- return __awaiter(this, void 0, void 0, function* () {
263
- try {
264
- const response = yield fetch(gateway, {
265
- body: '{"jsonrpc":"2.0","id":1,"method":"Connect","params":{}}',
266
- method: 'POST',
267
- headers: {
268
- 'content-type': 'application/json',
269
- authorization: `Bearer ${token}`,
270
- },
271
- signal,
272
- });
273
- const schema = z.union([
274
- z.object({
275
- result: z.object({
276
- token: z.string(),
277
- }),
278
- }),
279
- z.object({
280
- error: z.object({
281
- message: z.string(),
282
- }),
283
- }),
284
- ]);
285
- const body = schema.parse(yield response.json());
286
- if ('result' in body) {
287
- return Token.parse(body.result.token);
288
- }
289
- else {
290
- console.error(`gateway rejected token; ${body.error.message}`);
291
- return success('rejected');
292
- }
293
- }
294
- catch (error) {
295
- return failure(String(error));
296
- }
297
- });
298
- }
299
- //# sourceMappingURL=roomConnection.js.map
@@ -1,49 +0,0 @@
1
- import * as z from 'zod';
2
- import { Result, RpcMessage } from '@4players/odin-common';
3
- export declare function connect(url: URL, signal: AbortSignal): Promise<Result<WebSocket>>;
4
- export declare function connectOnce(url: URL, signal: AbortSignal): Promise<Result<WebSocket>>;
5
- export declare class RpcConnection {
6
- readonly webSocket: WebSocket;
7
- private readonly _SendQueue;
8
- private readonly _RecvQueue;
9
- private readonly _Requests;
10
- private readonly _Close;
11
- private _NextId;
12
- get closed(): boolean;
13
- get closeSignal(): AbortSignal;
14
- constructor(webSocket: WebSocket);
15
- request(name: string, properties: unknown): Promise<Result<unknown> | 'closed'>;
16
- request(name: string, properties: unknown, timeout: number): Promise<Result<unknown> | 'closed' | 'timeout'>;
17
- notify(name: string, properties: unknown): void;
18
- recv(): Promise<RpcMessage | 'closed'>;
19
- close(): void;
20
- private _TimeoutRequest;
21
- private _Send;
22
- private _OnWebSocketOpen;
23
- private _OnWebSocketMessage;
24
- private _OnResponse;
25
- private _OnEvent;
26
- private _Cleanup;
27
- }
28
- export type Commands = Record<string, {
29
- request: z.ZodTypeAny;
30
- response: z.ZodTypeAny;
31
- }>;
32
- export type Events = Record<string, z.ZodTypeAny>;
33
- export interface TypedRpcMessage<Name extends string, Properties> extends RpcMessage {
34
- name: Name;
35
- properties: Properties;
36
- }
37
- export type RealizedEvents<E extends Events> = {
38
- [Name in Extract<keyof E, string>]: TypedRpcMessage<Name, z.infer<E[Name]>>;
39
- }[Extract<keyof E, string>];
40
- export declare class TypedRpcConnection<C extends Commands, E extends Events> extends RpcConnection {
41
- readonly _Commands: C;
42
- readonly _Events: E;
43
- constructor(webSocket: WebSocket, _Commands: C, _Events: E);
44
- request<Name extends Extract<keyof C, string>>(name: Name, properties: z.infer<C[Name]['request']>): Promise<Result<z.infer<C[Name]['response']>> | 'closed'>;
45
- request<Name extends Extract<keyof C, string>>(name: Name, properties: z.infer<C[Name]['request']>, timeout: number): Promise<Result<z.infer<C[Name]['response']>> | 'closed' | 'timeout'>;
46
- notify<Name extends Extract<keyof C, string>>(name: Name, properties: z.infer<C[Name]['request']>): void;
47
- recv(): Promise<RealizedEvents<E> | 'closed'>;
48
- }
49
- //# sourceMappingURL=rpcConnection.d.ts.map
@@ -1,235 +0,0 @@
1
- /* eslint-disable no-dupe-class-members */
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- import * as msgpack from '@msgpack/msgpack';
12
- import { failure, success, isKnownRpcMessage, parseRpc, parseRpcMessage, abortableSleep, } from '@4players/odin-common';
13
- import { ConnectInterval } from './config';
14
- export function connect(url, signal) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- console.debug(`connecting to ${url}`);
17
- const start = performance.now();
18
- let connection = failure('no connection was attempted');
19
- for (let failures = 0; failures < ConnectInterval.length && signal.aborted === false; failures++) {
20
- const nextReconnectAt = start + whenToConnect(failures);
21
- if ((yield abortableSleep(nextReconnectAt - performance.now(), signal)) ===
22
- 'aborted') {
23
- return failure('aborted');
24
- }
25
- connection = yield connectOnce(url, signal);
26
- if (connection.type === 'Success') {
27
- return connection;
28
- }
29
- }
30
- return connection;
31
- });
32
- }
33
- export function connectOnce(url, signal) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- let webSocket;
36
- try {
37
- webSocket = new WebSocket(url);
38
- }
39
- catch (reason) {
40
- return failure(`unable to create websocket; ${reason}`);
41
- }
42
- const abort = new AbortController();
43
- const onOpen = new Promise((accept) => webSocket.addEventListener('open', () => accept(success(webSocket)), {
44
- signal: abort.signal,
45
- }));
46
- const onClose = new Promise((accept) => webSocket.addEventListener('close', (event) => accept(failure(event.reason)), { signal: abort.signal }));
47
- const onAbort = new Promise((accept) => signal.addEventListener('abort', () => accept(failure('aborted')), {
48
- signal: abort.signal,
49
- }));
50
- const result = yield Promise.race([onOpen, onClose, onAbort]);
51
- abort.abort();
52
- return result;
53
- });
54
- }
55
- function whenToConnect(failures) {
56
- const past_connects = ConnectInterval.slice(0, failures).reduce((a, b) => a + b, 0);
57
- const interval = ConnectInterval[failures] * Math.random();
58
- return past_connects + interval;
59
- }
60
- export class RpcConnection {
61
- get closed() {
62
- return this._Close.signal.aborted;
63
- }
64
- get closeSignal() {
65
- return this._Close.signal;
66
- }
67
- constructor(webSocket) {
68
- this.webSocket = webSocket;
69
- this._SendQueue = [];
70
- this._RecvQueue = [];
71
- this._Requests = new Map();
72
- this._Close = new AbortController();
73
- this._NextId = 1;
74
- this.webSocket.addEventListener('open', this._OnWebSocketOpen.bind(this));
75
- this.webSocket.addEventListener('close', this.close.bind(this));
76
- this.webSocket.addEventListener('message', this._OnWebSocketMessage.bind(this));
77
- this.webSocket.binaryType = 'arraybuffer';
78
- this._Close.signal.addEventListener('abort', this._Cleanup.bind(this), {
79
- once: true,
80
- });
81
- }
82
- request(name, properties, timeout) {
83
- return __awaiter(this, void 0, void 0, function* () {
84
- if (this.closed) {
85
- return Promise.resolve('closed');
86
- }
87
- const id = this._NextId;
88
- const timeoutId = timeout === undefined
89
- ? undefined
90
- : setTimeout(() => this._TimeoutRequest(id), timeout);
91
- this._Send([0, id, name, properties]);
92
- return new Promise((accept) => {
93
- this._Requests.set(id, { accept, timeoutId });
94
- this._NextId += 1;
95
- });
96
- });
97
- }
98
- notify(name, properties) {
99
- if (this.closed === false) {
100
- this._Send([2, name, properties]);
101
- }
102
- }
103
- recv() {
104
- if (this.closed === false) {
105
- return new Promise((accept) => this._RecvQueue.push(accept));
106
- }
107
- else {
108
- return Promise.resolve('closed');
109
- }
110
- }
111
- close() {
112
- this._Close.abort();
113
- }
114
- _TimeoutRequest(requestId) {
115
- const request = this._Requests.get(requestId);
116
- if (request === undefined)
117
- return;
118
- this._Requests.delete(requestId);
119
- clearTimeout(request.timeoutId);
120
- request.accept('timeout');
121
- }
122
- _Send(message) {
123
- this.webSocket.send(msgpack.encode(message));
124
- }
125
- _OnWebSocketOpen(ev) {
126
- for (const data in this._SendQueue) {
127
- this.webSocket.send(data);
128
- }
129
- this._SendQueue.length = 0;
130
- }
131
- _OnWebSocketMessage(ev) {
132
- const rpc = parseRpc(ev.data);
133
- if (rpc.type !== 'Success') {
134
- this.webSocket.close();
135
- return;
136
- }
137
- switch (rpc.value[0]) {
138
- case 0:
139
- this._Send([1, rpc.value[1], 'not supported', undefined]);
140
- break;
141
- case 1:
142
- this._OnResponse(rpc.value[1], rpc.value[2], rpc.value[3]);
143
- break;
144
- case 2:
145
- this._OnEvent(rpc.value[1], rpc.value[2]);
146
- break;
147
- }
148
- }
149
- _OnResponse(id, error, result) {
150
- const request = this._Requests.get(id);
151
- if (request === undefined)
152
- return;
153
- clearTimeout(request.timeoutId);
154
- request.accept(error === null ? success(result) : failure(error));
155
- }
156
- _OnEvent(name, properties) {
157
- console.log('event', name, properties);
158
- const receiver = this._RecvQueue.shift();
159
- if (receiver !== undefined) {
160
- receiver({ name, properties });
161
- }
162
- }
163
- _Cleanup() {
164
- console.log(`cleanup ${this.webSocket.url}`);
165
- for (const request of this._Requests.values()) {
166
- clearTimeout(request.timeoutId);
167
- request.accept('closed');
168
- }
169
- this._Requests.clear();
170
- for (const accept of this._RecvQueue) {
171
- accept('closed');
172
- }
173
- this._RecvQueue.length = 0;
174
- this._SendQueue.length = 0;
175
- this.webSocket.close();
176
- }
177
- }
178
- export class TypedRpcConnection extends RpcConnection {
179
- constructor(webSocket, _Commands, _Events) {
180
- super(webSocket);
181
- this._Commands = _Commands;
182
- this._Events = _Events;
183
- }
184
- request(name, properties, timeout) {
185
- const _super = Object.create(null, {
186
- request: { get: () => super.request }
187
- });
188
- return __awaiter(this, void 0, void 0, function* () {
189
- properties = this._Commands[name].request.parse(properties);
190
- const response = yield (timeout !== undefined
191
- ? _super.request.call(this, name, properties, timeout)
192
- : _super.request.call(this, name, properties));
193
- if (response === 'closed' ||
194
- response === 'timeout' ||
195
- response.type === 'Failure') {
196
- return response;
197
- }
198
- const parsed = this._Commands[name].response.safeParse(response.value);
199
- if (parsed.success) {
200
- response.value = parsed.data;
201
- return response;
202
- }
203
- else {
204
- return failure(`response schema failed validation: ${parsed.error}`);
205
- }
206
- });
207
- }
208
- notify(name, properties) {
209
- properties = this._Commands[name].request.parse(properties);
210
- super.notify(name, properties);
211
- }
212
- recv() {
213
- const _super = Object.create(null, {
214
- recv: { get: () => super.recv }
215
- });
216
- return __awaiter(this, void 0, void 0, function* () {
217
- const event = yield _super.recv.call(this);
218
- if (event === 'closed')
219
- return event;
220
- const parsed = parseRpcMessage(this._Events, event);
221
- if (parsed !== undefined) {
222
- return parsed;
223
- }
224
- if (!isKnownRpcMessage(this._Events, event.name)) {
225
- console.warn(`dropping unknown event ${event.name}`);
226
- }
227
- else {
228
- console.error(`schema validation for ${event.name} failed; closing connection`);
229
- this.close();
230
- }
231
- return 'closed';
232
- });
233
- }
234
- }
235
- //# sourceMappingURL=rpcConnection.js.map
@@ -1,16 +0,0 @@
1
- import * as z from 'zod';
2
- import { TokenAudienceSchema, TokenClaimsSchema, Result } from '@4players/odin-common';
3
- export type TokenClaims = z.infer<typeof TokenClaimsSchema>;
4
- export declare class Token {
5
- readonly text: string;
6
- readonly claims: TokenClaims;
7
- static parse(token: string): Result<Token>;
8
- private readonly _Address;
9
- protected constructor(text: string, claims: TokenClaims);
10
- get timeLeft(): number;
11
- get address(): URL | undefined;
12
- get defaultRoomId(): string | undefined;
13
- hasAudience(audience: z.infer<typeof TokenAudienceSchema>): boolean;
14
- toString(): string;
15
- }
16
- //# sourceMappingURL=token.d.ts.map
@@ -1,67 +0,0 @@
1
- import { TokenClaimsSchema, failure, fromBase64Url, success, } from '@4players/odin-common';
2
- export class Token {
3
- static parse(token) {
4
- const segments = token.split('.');
5
- if (segments.length !== 3)
6
- return failure('expected three segments');
7
- const body = fromBase64Url(segments[1]);
8
- if (body.type === 'Failure') {
9
- return failure(`invalid token; ${body.reason}`);
10
- }
11
- let json;
12
- try {
13
- json = JSON.parse(body.value);
14
- }
15
- catch (reason) {
16
- return failure(`invalid token; ${reason}`);
17
- }
18
- const parsed = TokenClaimsSchema.safeParse(json);
19
- if (parsed.success === false) {
20
- return failure(`invalid token; ${parsed.error}`);
21
- }
22
- return success(new Token(token, parsed.data));
23
- }
24
- constructor(text, claims) {
25
- this.text = text;
26
- this.claims = claims;
27
- const address = claims.adr;
28
- if (address !== undefined) {
29
- try {
30
- this._Address = new URL(`wss://${address}`);
31
- }
32
- catch (error) {
33
- console.error(`address in token(${address}) can not be parsed; ${error}`);
34
- }
35
- }
36
- }
37
- get timeLeft() {
38
- if (this.claims.exp === undefined)
39
- return Infinity;
40
- return this.claims.exp * 1000 - Date.now();
41
- }
42
- get address() {
43
- return this._Address;
44
- }
45
- get defaultRoomId() {
46
- if (Array.isArray(this.claims.rid)) {
47
- return this.claims.rid.length === 1 ? this.claims.rid[0] : undefined;
48
- }
49
- else {
50
- return this.claims.rid;
51
- }
52
- }
53
- hasAudience(audience) {
54
- if (this.claims.aud === undefined)
55
- return true;
56
- if (Array.isArray(this.claims.aud)) {
57
- return this.claims.aud.includes(audience);
58
- }
59
- else {
60
- return this.claims.aud === audience;
61
- }
62
- }
63
- toString() {
64
- return this.text;
65
- }
66
- }
67
- //# sourceMappingURL=token.js.map