@4players/odin-plugin-web 1.0.0-alpha.20 → 1.0.0-alpha.22

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 } from '@4players/odin-common';
1
+ import { Result, Backend } from '@4players/odin-common';
2
2
  import { DatagramHandler, MainConnection } from './mainConnection';
3
- import { Transport } from './index';
3
+ import Transport = Backend.Transport;
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,6 +1,5 @@
1
1
  import { ConnectionStatus, type DatagramHandler, type MainConnection } from '../mainConnection';
2
- import { MainCommands, MainNotifications, PeerId, Result } from '@4players/odin-common';
3
- import { Transport } from '..';
2
+ import { MainCommands, MainNotifications, PeerId, Result, Backend } from '@4players/odin-common';
4
3
  import { Token } from '../token';
5
4
  import { RpcConnection, TypedRpcConnection } from '../rpcConnection';
6
5
  export declare class H3MainConnection implements MainConnection {
@@ -13,7 +12,7 @@ export declare class H3MainConnection implements MainConnection {
13
12
  readonly closePromise: Promise<'closed'>;
14
13
  readonly datagramWriter: WritableStreamDefaultWriter<Uint8Array>;
15
14
  get closeSignal(): AbortSignal;
16
- get transport(): Transport;
15
+ get transport(): Backend.Transport;
17
16
  get closed(): boolean;
18
17
  static create(id: number, address: string, onDatagram: DatagramHandler, signal: AbortSignal): Promise<Result<MainConnection>>;
19
18
  private constructor();
@@ -8,12 +8,13 @@ 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, } from '@4players/odin-common';
12
- import { logger, Transport } from '..';
11
+ import { MainCommandsRpc, MainNotificationsRpc, RoomCommandsRpc, RoomNotificationsRpc, failure, success, Backend, } from '@4players/odin-common';
12
+ import { logger } from '..';
13
13
  import { Token } from '../token';
14
14
  import { RpcConnection, TypedRpcConnection } from '../rpcConnection';
15
15
  import { HealthCheckTimeout } from '../config';
16
16
  import * as pkg from '../../../package.json';
17
+ var Transport = Backend.Transport;
17
18
  export class H3MainConnection {
18
19
  get closeSignal() {
19
20
  return this.closeController.signal;
@@ -7,6 +7,7 @@ import { VideoCapture } from './medias/video-capture';
7
7
  import { VideoPlayback } from './medias/video-playback';
8
8
  import { AudioPlayback } from './medias/audio-playback';
9
9
  import JoinRoomParameters = Backend.JoinRoomParameters;
10
+ import Cipher = Backend.Cipher;
10
11
  export type { LogFilters } from '@4players/odin-common';
11
12
  export { logger } from './config';
12
13
  type Plugin = Backend.Plugin;
@@ -14,22 +15,15 @@ export interface DeviceParameters {
14
15
  readonly device?: Device;
15
16
  onStatusChanged?: Backend.OnStatusChanged;
16
17
  }
17
- export declare enum Transport {
18
- H3 = "h3",
19
- WebRTC = "webrtc"
20
- }
21
- export interface WebPluginOptions {
22
- transport: Transport;
23
- }
24
18
  export declare class WebPlugin implements Plugin {
25
- readonly options: WebPluginOptions;
26
- readonly version = "2";
19
+ readonly version = "3";
20
+ readonly supportedTransports: Backend.Transport[];
27
21
  private _NextRoomId;
28
22
  private _PlaybackVolume;
29
23
  private readonly _ConnectionPool;
30
24
  private readonly _MediaController;
31
25
  get playbackVolume(): Backend.Volume;
32
- static create(audioContextFactory: AudioContextFactory, options?: WebPluginOptions): Promise<WebPlugin>;
26
+ static create(audioContextFactory: AudioContextFactory): Promise<WebPlugin>;
33
27
  private constructor();
34
28
  joinRoom(parameters: JoinRoomParameters): Room;
35
29
  createAudioPlayback(parameters: CreateAudioPlaybackParameters): Promise<AudioPlayback>;
@@ -50,9 +44,9 @@ export declare class Room implements Backend.Room {
50
44
  private readonly _Peers;
51
45
  private readonly _AvailableMediaIds;
52
46
  get mainConnection(): MainConnection | undefined;
53
- constructor(id: number, connectionPool: ConnectionPool, parameters: JoinRoomParameters, options: WebPluginOptions);
47
+ constructor(id: number, connectionPool: ConnectionPool, parameters: JoinRoomParameters);
54
48
  get token(): string;
55
- get cipher(): Backend.Cipher | undefined;
49
+ get cipher(): Cipher | undefined;
56
50
  request(method: string, properties: unknown): Promise<unknown>;
57
51
  link(media: Backend.Media): Promise<void>;
58
52
  unlink(media: Backend.Media): 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 { assert, generateUUID, OdinError, RoomNotificationsRpc, unwrap, } from '@4players/odin-common';
10
+ import { assert, Backend, 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,17 +19,13 @@ 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;
22
23
  export { logger } from './config';
23
- export var Transport;
24
- (function (Transport) {
25
- Transport["H3"] = "h3";
26
- Transport["WebRTC"] = "webrtc";
27
- })(Transport || (Transport = {}));
28
24
  export class WebPlugin {
29
25
  get playbackVolume() {
30
26
  return this._PlaybackVolume;
31
27
  }
32
- static create(audioContextFactory, options) {
28
+ static create(audioContextFactory) {
33
29
  return __awaiter(this, void 0, void 0, function* () {
34
30
  logger.info(['Other'], 'Using ODIN Plugin Web!');
35
31
  // eslint-disable-next-line prefer-const
@@ -37,19 +33,19 @@ export class WebPlugin {
37
33
  const pool = new ConnectionPool((connectionId, packet) => audioController.receivePacket(connectionId, packet));
38
34
  const audioContexts = new AudioContextCollection(audioContextFactory);
39
35
  audioController = new MediaController(audioContexts, pool.sendDatagram.bind(pool));
40
- return new WebPlugin(pool, audioController, options);
36
+ return new WebPlugin(pool, audioController);
41
37
  });
42
38
  }
43
- constructor(connectionPool, audioController, options = { transport: Transport.H3 }) {
44
- this.options = options;
45
- this.version = '2';
39
+ constructor(connectionPool, audioController) {
40
+ this.version = '3';
41
+ this.supportedTransports = [Transport.WebRTC, Transport.H3];
46
42
  this._NextRoomId = 0;
47
43
  this._PlaybackVolume = 1;
48
44
  this._ConnectionPool = connectionPool;
49
45
  this._MediaController = audioController;
50
46
  }
51
47
  joinRoom(parameters) {
52
- return new Room(this._NextRoomId++, this._ConnectionPool, parameters, this.options);
48
+ return new Room(this._NextRoomId++, this._ConnectionPool, parameters);
53
49
  }
54
50
  createAudioPlayback(parameters) {
55
51
  return __awaiter(this, void 0, void 0, function* () {
@@ -58,6 +54,7 @@ export class WebPlugin {
58
54
  }
59
55
  createAudioCapture(parameters) {
60
56
  return __awaiter(this, void 0, void 0, function* () {
57
+ console.log('Eyvor createAudioCapture: ', parameters);
61
58
  return this._MediaController.createAudioCapture(parameters);
62
59
  });
63
60
  }
@@ -92,7 +89,7 @@ export class Room {
92
89
  get mainConnection() {
93
90
  return this._Connection.mainConnection;
94
91
  }
95
- constructor(id, connectionPool, parameters, options) {
92
+ constructor(id, connectionPool, parameters) {
96
93
  var _a, _b, _c;
97
94
  this._Captures = new Map();
98
95
  this._Playbacks = new Map();
@@ -106,7 +103,7 @@ export class Room {
106
103
  assert(roomId !== undefined, 'room id required for multi-room-tokens');
107
104
  this._Id = id;
108
105
  this._OnEvent = onEvent;
109
- this._Connection = new RoomConnection(connectionPool, options.transport, this._HandleEvent.bind(this), gateway ? new URL(gateway) : undefined, token, roomId, userData, position);
106
+ this._Connection = new RoomConnection(connectionPool, parameters.transport ? parameters.transport : Transport.H3, this._HandleEvent.bind(this), gateway ? new URL(gateway) : undefined, token, roomId, userData, position);
110
107
  }
111
108
  get token() {
112
109
  return this._Connection.token.text;
@@ -180,15 +177,19 @@ export class Room {
180
177
  }
181
178
  }
182
179
  else if (media instanceof VideoPlayback) {
180
+ logger.log(['Video'], 'Room.link() VideoPlayback: ', media);
183
181
  const entry = (_c = this._Playbacks.get(media.uid)) !== null && _c !== void 0 ? _c : {
184
182
  media: undefined,
185
183
  playback: undefined,
186
184
  };
185
+ logger.log(['Video'], 'Room.link() VideoPlayback entry: ', entry);
187
186
  if (entry.playback !== undefined) {
188
187
  this.unlink(entry.playback);
189
188
  }
190
189
  if (entry.media !== undefined) {
190
+ logger.log(['Video'], 'Room.link() VideoPlayback before startRemoteVideo: ', entry);
191
191
  const track = yield ((_d = this.mainConnection) === null || _d === void 0 ? void 0 : _d.startRemoteVideo(entry.media.mediaId));
192
+ logger.log(['Video'], 'Room.link() VideoPlayback track: ', track);
192
193
  if (track) {
193
194
  media.setMediaStream(new MediaStream([track]));
194
195
  }
@@ -1,7 +1,7 @@
1
- import { Result } from '@4players/odin-common';
1
+ import { Backend, Result } from '@4players/odin-common';
2
2
  import { Token } from './token';
3
- import { Transport } from './index';
4
3
  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,7 +1,9 @@
1
1
  /* eslint-disable no-dupe-class-members */
2
- import { logger, Transport } from './index';
2
+ import { Backend } from '@4players/odin-common';
3
+ import { logger } from './index';
3
4
  import { WebRtcMainConnection } from './webrtc/mainConnection';
4
5
  import { H3MainConnection } from './h3/mainConnection';
6
+ var Transport = Backend.Transport;
5
7
  export function createMainConnection(id, transport, address, onDatagram, signal) {
6
8
  logger.log(['Connection'], 'createMainConnection() ', transport, address);
7
9
  switch (transport) {
@@ -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 } from './index';
5
+ import Transport = Backend.Transport;
6
6
  export declare class RoomConnection implements RoomConnection {
7
7
  readonly connectionPool: ConnectionPool;
8
8
  readonly transport: Transport;
@@ -1,8 +1,7 @@
1
- import { MainCommands, MainNotifications, Result } from '@4players/odin-common';
1
+ import { MainCommands, MainNotifications, Result, Backend } 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';
6
5
  export declare class WebRtcMainConnection implements MainConnection {
7
6
  readonly id: number;
8
7
  readonly address: string;
@@ -22,7 +21,7 @@ export declare class WebRtcMainConnection implements MainConnection {
22
21
  private _Negotiation;
23
22
  private _ResolveOffer?;
24
23
  private _awaitingRemoteTracks;
25
- get transport(): Transport;
24
+ get transport(): Backend.Transport;
26
25
  get closePromise(): Promise<"closed">;
27
26
  get closeSignal(): AbortSignal;
28
27
  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, } from '@4players/odin-common';
10
+ import { MainCommandsRpc, MainNotificationsRpc, assert, extendUrl, failure, success, fail, Backend, } 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
- import { Transport } from '../index';
16
+ var Transport = Backend.Transport;
17
17
  export class WebRtcMainConnection {
18
18
  static create(id, address, onDatagram, signal) {
19
19
  return __awaiter(this, void 0, void 0, function* () {