@4players/odin-plugin-web 1.0.0-alpha.16 → 1.0.0-alpha.18

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,6 +1,6 @@
1
- import { Result, Backend } from '@4players/odin-common';
1
+ import { Result } from '@4players/odin-common';
2
2
  import { DatagramHandler, MainConnection } from './mainConnection';
3
- import Transport = Backend.Transport;
3
+ import { Transport } from './index';
4
4
  export declare class ConnectionPool {
5
5
  readonly onDatagram: DatagramHandler;
6
6
  private _LastConnectionId;
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { failure, nextTick, success, } from '@4players/odin-common';
10
+ import { failure, nextTick, success } from '@4players/odin-common';
11
11
  import { ClockJumpCheckInterval, ClockJumpThreshold, logger } from './config';
12
12
  import { createMainConnection, } from './mainConnection';
13
13
  export class ConnectionPool {
@@ -99,7 +99,9 @@ export class ConnectionPool {
99
99
  });
100
100
  }
101
101
  releaseConnection(connection) {
102
+ logger.log(['Connection'], 'ConnectionPool.releaseConnection()');
102
103
  const entry = this._ConnectionsById.get(connection.id);
104
+ logger.log(['Connection'], 'ConnectionPool.releaseConnection() entry refs', entry === null || entry === void 0 ? void 0 : entry.references);
103
105
  if (entry === undefined)
104
106
  return;
105
107
  if (entry.status === 'init') {
@@ -1,15 +1,8 @@
1
1
  import { ConnectionStatus, type DatagramHandler, type MainConnection } from '../mainConnection';
2
- import { MainCommands, MainNotifications, PeerId, Result, Backend } from '@4players/odin-common';
2
+ import { MainCommands, MainNotifications, PeerId, Result } from '@4players/odin-common';
3
+ import { Transport } from '..';
3
4
  import { Token } from '../token';
4
5
  import { RpcConnection, TypedRpcConnection } from '../rpcConnection';
5
- type IncomingStream = {
6
- type: 'waiting';
7
- resolve: (stream: WebTransportBidirectionalStream) => void;
8
- } | {
9
- type: 'received';
10
- stream: WebTransportBidirectionalStream;
11
- timeout: ReturnType<typeof setTimeout>;
12
- };
13
6
  export declare class H3MainConnection implements MainConnection {
14
7
  readonly id: number;
15
8
  readonly address: string;
@@ -17,11 +10,10 @@ export declare class H3MainConnection implements MainConnection {
17
10
  readonly rpc: TypedRpcConnection<MainCommands, MainNotifications>;
18
11
  readonly closeController: AbortController;
19
12
  status: ConnectionStatus;
20
- readonly incomingStreams: Map<number, IncomingStream>;
21
13
  readonly closePromise: Promise<'closed'>;
22
14
  readonly datagramWriter: WritableStreamDefaultWriter<Uint8Array>;
23
15
  get closeSignal(): AbortSignal;
24
- get transport(): Backend.Transport;
16
+ get transport(): Transport;
25
17
  get closed(): boolean;
26
18
  static create(id: number, address: string, onDatagram: DatagramHandler, signal: AbortSignal): Promise<Result<MainConnection>>;
27
19
  private constructor();
@@ -37,4 +29,3 @@ export declare class H3MainConnection implements MainConnection {
37
29
  stopRemoteVideo(mediaId: number): void;
38
30
  private _Request;
39
31
  }
40
- export {};
@@ -8,13 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { ConnectionStatus, } from '../mainConnection';
11
- import { MainCommandsRpc, MainNotificationsRpc, RoomCommandsRpc, RoomNotificationsRpc, failure, success, Backend, } from '@4players/odin-common';
12
- import { logger } from '..';
11
+ import { MainCommandsRpc, MainNotificationsRpc, RoomCommandsRpc, RoomNotificationsRpc, failure, success, } from '@4players/odin-common';
12
+ import { logger, Transport } from '..';
13
13
  import { Token } from '../token';
14
14
  import { RpcConnection, TypedRpcConnection } from '../rpcConnection';
15
15
  import { HealthCheckTimeout } from '../config';
16
16
  import { version } from '../../version';
17
- var Transport = Backend.Transport;
18
17
  export class H3MainConnection {
19
18
  get closeSignal() {
20
19
  return this.closeController.signal;
@@ -63,7 +62,6 @@ export class H3MainConnection {
63
62
  this.rpc = rpc;
64
63
  this.closeController = closeController;
65
64
  this.status = ConnectionStatus.Connecting;
66
- this.incomingStreams = new Map();
67
65
  logger.info(['Connection', 'H3'], 'H3MainConnection.constructor()');
68
66
  this.closePromise = (() => __awaiter(this, void 0, void 0, function* () {
69
67
  try {
@@ -14,14 +14,22 @@ export interface DeviceParameters {
14
14
  readonly device?: Device;
15
15
  onStatusChanged?: Backend.OnStatusChanged;
16
16
  }
17
+ export declare enum Transport {
18
+ H3 = "h3",
19
+ WebRTC = "webrtc"
20
+ }
21
+ export interface WebPluginOptions {
22
+ transport: Transport;
23
+ }
17
24
  export declare class WebPlugin implements Plugin {
25
+ readonly options: WebPluginOptions;
18
26
  readonly version = "1";
19
27
  private _NextRoomId;
20
28
  private _PlaybackVolume;
21
29
  private readonly _ConnectionPool;
22
30
  private readonly _MediaController;
23
31
  get playbackVolume(): Backend.Volume;
24
- static create(audioContextFactory: AudioContextFactory): Promise<WebPlugin>;
32
+ static create(audioContextFactory: AudioContextFactory, options?: WebPluginOptions): Promise<WebPlugin>;
25
33
  private constructor();
26
34
  joinRoom(parameters: JoinRoomParameters): Room;
27
35
  createAudioPlayback(parameters: CreateAudioPlaybackParameters): Promise<AudioPlayback>;
@@ -42,7 +50,7 @@ export declare class Room implements Backend.Room {
42
50
  private readonly _Peers;
43
51
  private readonly _AvailableMediaIds;
44
52
  get mainConnection(): MainConnection | undefined;
45
- constructor(id: number, connectionPool: ConnectionPool, parameters: JoinRoomParameters);
53
+ constructor(id: number, connectionPool: ConnectionPool, parameters: JoinRoomParameters, options: WebPluginOptions);
46
54
  get token(): string;
47
55
  request(method: string, properties: unknown): Promise<unknown>;
48
56
  link(media: Backend.Media): Promise<void>;
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Backend, assert, unwrap, RoomNotificationsRpc, generateUUID, OdinError, } from '@4players/odin-common';
10
+ import { assert, generateUUID, OdinError, RoomNotificationsRpc, unwrap, } from '@4players/odin-common';
11
11
  import { AudioContextCollection, MediaController, } from './mediaController';
12
12
  import { ConnectionPool } from './connectionPool';
13
13
  import { RoomConnection } from './roomConnection';
@@ -19,13 +19,17 @@ import { VideoCapture } from './medias/video-capture';
19
19
  import { VideoPlayback } from './medias/video-playback';
20
20
  import { AudioPlayback } from './medias/audio-playback';
21
21
  import { logger } from './config';
22
- var Transport = Backend.Transport;
23
22
  export { logger } from './config';
23
+ export var Transport;
24
+ (function (Transport) {
25
+ Transport["H3"] = "h3";
26
+ Transport["WebRTC"] = "webrtc";
27
+ })(Transport || (Transport = {}));
24
28
  export class WebPlugin {
25
29
  get playbackVolume() {
26
30
  return this._PlaybackVolume;
27
31
  }
28
- static create(audioContextFactory) {
32
+ static create(audioContextFactory, options) {
29
33
  return __awaiter(this, void 0, void 0, function* () {
30
34
  logger.info(['Other'], 'Using ODIN Plugin Web!');
31
35
  // eslint-disable-next-line prefer-const
@@ -33,10 +37,11 @@ export class WebPlugin {
33
37
  const pool = new ConnectionPool((connectionId, packet) => audioController.receivePacket(connectionId, packet));
34
38
  const audioContexts = new AudioContextCollection(audioContextFactory);
35
39
  audioController = new MediaController(audioContexts, pool.sendDatagram.bind(pool));
36
- return new WebPlugin(pool, audioController);
40
+ return new WebPlugin(pool, audioController, options);
37
41
  });
38
42
  }
39
- constructor(connectionPool, audioController) {
43
+ constructor(connectionPool, audioController, options = { transport: Transport.H3 }) {
44
+ this.options = options;
40
45
  this.version = '1';
41
46
  this._NextRoomId = 0;
42
47
  this._PlaybackVolume = 1;
@@ -44,7 +49,7 @@ export class WebPlugin {
44
49
  this._MediaController = audioController;
45
50
  }
46
51
  joinRoom(parameters) {
47
- return new Room(this._NextRoomId++, this._ConnectionPool, parameters);
52
+ return new Room(this._NextRoomId++, this._ConnectionPool, parameters, this.options);
48
53
  }
49
54
  createAudioPlayback(parameters) {
50
55
  return __awaiter(this, void 0, void 0, function* () {
@@ -87,8 +92,8 @@ export class Room {
87
92
  get mainConnection() {
88
93
  return this._Connection.mainConnection;
89
94
  }
90
- constructor(id, connectionPool, parameters) {
91
- var _a, _b, _c, _d;
95
+ constructor(id, connectionPool, parameters, options) {
96
+ var _a, _b, _c;
92
97
  this._Captures = new Map();
93
98
  this._Playbacks = new Map();
94
99
  this._Peers = new Map();
@@ -101,7 +106,7 @@ export class Room {
101
106
  assert(roomId !== undefined, 'room id required for multi-room-tokens');
102
107
  this._Id = id;
103
108
  this._OnEvent = onEvent;
104
- this._Connection = new RoomConnection(connectionPool, (_d = parameters.transport) !== null && _d !== void 0 ? _d : Transport.H3, this._HandleEvent.bind(this), gateway ? new URL(gateway) : undefined, token, roomId, userData, position);
109
+ this._Connection = new RoomConnection(connectionPool, options.transport, this._HandleEvent.bind(this), gateway ? new URL(gateway) : undefined, token, roomId, userData, position);
105
110
  }
106
111
  get token() {
107
112
  return this._Connection.token.text;
@@ -112,6 +117,7 @@ export class Room {
112
117
  link(media) {
113
118
  return __awaiter(this, void 0, void 0, function* () {
114
119
  var _a, _b, _c, _d;
120
+ logger.debug(['Audio'], 'Room.link() media', media);
115
121
  if (media instanceof AudioPlayback) {
116
122
  const entry = (_a = this._Playbacks.get(media.uid)) !== null && _a !== void 0 ? _a : {
117
123
  media: undefined,
@@ -194,6 +200,7 @@ export class Room {
194
200
  }
195
201
  unlink(media) {
196
202
  var _a, _b;
203
+ logger.debug(['Audio'], 'Room.unlink() media', media);
197
204
  if (media instanceof AudioPlayback || media instanceof VideoPlayback) {
198
205
  const entry = this._Playbacks.get(media.uid);
199
206
  if ((entry === null || entry === void 0 ? void 0 : entry.playback) !== media)
@@ -1,7 +1,7 @@
1
- import { Backend, Result } from '@4players/odin-common';
1
+ import { Result } from '@4players/odin-common';
2
2
  import { Token } from './token';
3
+ import { Transport } from './index';
3
4
  import { RpcConnection } from './rpcConnection';
4
- import Transport = Backend.Transport;
5
5
  export type DatagramHandler = (connectionId: number, datagram: Uint8Array) => void;
6
6
  export declare function createMainConnection(id: number, transport: Transport, address: string, onDatagram: DatagramHandler, signal: AbortSignal): Promise<Result<MainConnection>>;
7
7
  export declare enum ConnectionStatus {
@@ -1,9 +1,7 @@
1
1
  /* eslint-disable no-dupe-class-members */
2
- import { Backend } from '@4players/odin-common';
3
- import { logger } from './index';
2
+ import { logger, Transport } from './index';
4
3
  import { WebRtcMainConnection } from './webrtc/mainConnection';
5
4
  import { H3MainConnection } from './h3/mainConnection';
6
- var Transport = Backend.Transport;
7
5
  export function createMainConnection(id, transport, address, onDatagram, signal) {
8
6
  logger.log(['Connection'], 'createMainConnection() ', transport, address);
9
7
  switch (transport) {
@@ -61,6 +61,7 @@ export class AudioCapture {
61
61
  this._Volume = 1;
62
62
  this._DeviceCb = () => __awaiter(this, void 0, void 0, function* () {
63
63
  var _a, _b;
64
+ logger.debug(['Audio'], 'AudioCapture._DeviceCb()');
64
65
  const devices = yield enumerateDevices();
65
66
  const isListed = devices.some((device) => {
66
67
  var _a, _b;
@@ -84,6 +85,7 @@ export class AudioCapture {
84
85
  }
85
86
  start(room, media, uid) {
86
87
  var _a;
88
+ logger.debug(['Audio'], 'AudioCapture.start()', media);
87
89
  let entry = this._Medias.get(media.connectionId);
88
90
  if (entry === undefined) {
89
91
  this._Medias.set(media.connectionId, (entry = new Set()));
@@ -103,6 +105,7 @@ export class AudioCapture {
103
105
  }
104
106
  stop(room, media) {
105
107
  var _a;
108
+ logger.debug(['Audio'], 'AudioCapture.stop()', media);
106
109
  const entry = this._Medias.get(media.connectionId);
107
110
  if (!(entry === null || entry === void 0 ? void 0 : entry.delete(media.mediaId)))
108
111
  return;
@@ -114,6 +117,7 @@ export class AudioCapture {
114
117
  this._UpdateMedias();
115
118
  }
116
119
  setVad(value) {
120
+ logger.debug(['Audio'], 'AudioCapture.setVad() config', value);
117
121
  this._Vad = value;
118
122
  if (this._Capture) {
119
123
  this._Capture.worker.setVad(value);
@@ -121,6 +125,7 @@ export class AudioCapture {
121
125
  }
122
126
  setApm(config) {
123
127
  return __awaiter(this, void 0, void 0, function* () {
128
+ logger.debug(['Audio'], 'AudioCapture.setApm() config', config);
124
129
  this._Apm = config;
125
130
  if (this._DeviceParameters) {
126
131
  yield this.setDevice(this._DeviceParameters);
@@ -172,6 +177,7 @@ export class AudioCapture {
172
177
  }
173
178
  setVolume(value) {
174
179
  var _a;
180
+ logger.debug(['Audio'], 'AudioCapture.setVolume()', value);
175
181
  this._Volume = value;
176
182
  if (value === 'muted') {
177
183
  this.close();
@@ -184,6 +190,7 @@ export class AudioCapture {
184
190
  }
185
191
  }
186
192
  close() {
193
+ logger.debug(['Audio'], 'AudioCapture.close()');
187
194
  if (this._Capture !== undefined) {
188
195
  this._Capture.worker.close();
189
196
  stopMediaStream(this._Capture.source.mediaStream);
@@ -195,6 +202,7 @@ export class AudioCapture {
195
202
  }
196
203
  _UpdateMedias() {
197
204
  return __awaiter(this, void 0, void 0, function* () {
205
+ logger.debug(['Audio'], 'AudioCapture._UpdateMedias()');
198
206
  if (this._Capture !== undefined) {
199
207
  const connections = Array.from(this._Medias).map(([key, value]) => {
200
208
  return { id: key, mediaIds: Array.from(value) };
@@ -1,3 +1,4 @@
1
+ import { logger } from '../config';
1
2
  export class AudioPlayback {
2
3
  get volume() {
3
4
  return this.controller.playbackGetVolume(this.uid);
@@ -10,15 +11,19 @@ export class AudioPlayback {
10
11
  this.uid = uid;
11
12
  }
12
13
  start(id) {
14
+ logger.debug(['Audio'], 'AudioPlayback.start()', id);
13
15
  this.controller.playbackStart(this.uid, id);
14
16
  }
15
17
  stop(id) {
18
+ logger.debug(['Audio'], 'AudioPlayback.stop()', id);
16
19
  this.controller.playbackStop(this.uid, id);
17
20
  }
18
21
  setVolume(value) {
22
+ logger.debug(['Audio'], 'AudioPlayback.setVolume()', value);
19
23
  this.controller.playbackSetVolume(this.uid, value);
20
24
  }
21
25
  close() {
26
+ logger.debug(['Audio'], 'AudioPlayback.close()');
22
27
  this.controller.closePlayback(this.uid);
23
28
  }
24
29
  }
@@ -2,7 +2,7 @@ import { Backend, RoomCommands, Result, Infer } from '@4players/odin-common';
2
2
  import { ConnectionPool } from './connectionPool';
3
3
  import { MainConnection } from './mainConnection';
4
4
  import { Token } from './token';
5
- import Transport = Backend.Transport;
5
+ import { Transport } from './index';
6
6
  export declare class RoomConnection implements RoomConnection {
7
7
  readonly connectionPool: ConnectionPool;
8
8
  readonly transport: Transport;
@@ -215,6 +215,7 @@ export class RoomConnection {
215
215
  case 'closed':
216
216
  logger.debug(['Connection'], 'RoomConnection._HandleConnection: closed');
217
217
  (_a = this._RoomConnection) === null || _a === void 0 ? void 0 : _a.close();
218
+ this.connectionPool.releaseConnection(main);
218
219
  return;
219
220
  case 'renewToken':
220
221
  this._RenewToken();
@@ -1,7 +1,8 @@
1
- import { MainCommands, MainNotifications, Result, Backend } from '@4players/odin-common';
1
+ import { MainCommands, MainNotifications, Result } from '@4players/odin-common';
2
2
  import { type MainConnection, type DatagramHandler, ConnectionStatus } from '../mainConnection';
3
3
  import { Token } from '../token';
4
4
  import { RpcConnection, TypedRpcConnection } from '../rpcConnection';
5
+ import { Transport } from '../index';
5
6
  export declare class WebRtcMainConnection implements MainConnection {
6
7
  readonly id: number;
7
8
  readonly address: string;
@@ -21,7 +22,7 @@ export declare class WebRtcMainConnection implements MainConnection {
21
22
  private _Negotiation;
22
23
  private _ResolveOffer?;
23
24
  private _awaitingRemoteTracks;
24
- get transport(): Backend.Transport;
25
+ get transport(): Transport;
25
26
  get closePromise(): Promise<"closed">;
26
27
  get closeSignal(): AbortSignal;
27
28
  get closed(): boolean;
@@ -7,13 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { MainCommandsRpc, MainNotificationsRpc, assert, extendUrl, failure, success, fail, Backend, } from '@4players/odin-common';
10
+ import { MainCommandsRpc, MainNotificationsRpc, assert, extendUrl, failure, success, fail, } from '@4players/odin-common';
11
11
  import { ConnectionStatus, } from '../mainConnection';
12
12
  import { Token } from '../token';
13
13
  import { RpcConnection, TypedRpcConnection } from '../rpcConnection';
14
14
  import { connect } from './websocket';
15
15
  import { HealthCheckTimeout, logger, MainConnectionPingInterval, WebRtcIceTimeout, WebRtcTimeout, } from '../config';
16
- var Transport = Backend.Transport;
16
+ import { Transport } from '../index';
17
17
  export class WebRtcMainConnection {
18
18
  static create(id, address, onDatagram, signal) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.0.0-alpha.16";
1
+ export declare const version = "1.0.0-alpha.18";
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '1.0.0-alpha.16';
2
+ export const version = '1.0.0-alpha.18';