@4players/odin-plugin-web 1.0.0-alpha.15 → 1.0.0-alpha.17

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 {
@@ -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;
@@ -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) {
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { success } from '@4players/odin-common';
11
11
  import { Silence } from '../../worker/common';
12
+ import { logger } from '../index';
12
13
  import { createCaptureWorker } from '../../worker';
13
14
  import { openCaptureDevice, stopMediaStream, enumerateDevices, } from '../deviceManager';
14
15
  const defaultVad = {
@@ -71,7 +72,6 @@ export class AudioCapture {
71
72
  navigator.mediaDevices.removeEventListener('devicechange', this._DeviceCb);
72
73
  }
73
74
  });
74
- console.log('Eyvor AudioCapture constructor');
75
75
  if (parameters.apm) {
76
76
  this.setApm(parameters.apm);
77
77
  }
@@ -130,7 +130,7 @@ export class AudioCapture {
130
130
  setDevice(parameters) {
131
131
  return __awaiter(this, void 0, void 0, function* () {
132
132
  var _a;
133
- console.log('Eyvor AudioCapture setDevice() parameters: ', parameters);
133
+ logger.debug(['Device'], 'AudioCapture.setDevice() parameters: ', parameters);
134
134
  const rollbackParams = this._DeviceParameters;
135
135
  this._DeviceParameters = parameters;
136
136
  if (this._Volume === 'muted') {
@@ -138,7 +138,10 @@ export class AudioCapture {
138
138
  }
139
139
  const device = yield openCaptureDevice(this.controller, parameters, this._Apm);
140
140
  if (device.type !== 'Success') {
141
- console.error(`unable to open capture device; ${device.reason}`);
141
+ logger.error([
142
+ 'Device',
143
+ `AudioCapture.setDevice() Unable to open capture device; ${device.reason}`,
144
+ ]);
142
145
  this._DeviceParameters = rollbackParams;
143
146
  return;
144
147
  }
@@ -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;
@@ -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.15";
1
+ export declare const version = "1.0.0-alpha.17";
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '1.0.0-alpha.15';
2
+ export const version = '1.0.0-alpha.17';