@signalwire/js 1.3.0-dev.1 → 1.4.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.
Files changed (69) hide show
  1. package/README.md +4 -2
  2. package/dist/esm/common/src/BaseSession.d.ts +8 -13
  3. package/dist/esm/common/src/BaseSession.js +33 -46
  4. package/dist/esm/common/src/BrowserSession.d.ts +20 -57
  5. package/dist/esm/common/src/BrowserSession.js +91 -359
  6. package/dist/esm/common/src/messages/Verto.d.ts +1 -10
  7. package/dist/esm/common/src/messages/Verto.js +1 -16
  8. package/dist/esm/common/src/messages/verto/Login.d.ts +1 -13
  9. package/dist/esm/common/src/messages/verto/Login.js +2 -5
  10. package/dist/esm/common/src/services/BroadcastHandler.js +3 -2
  11. package/dist/esm/common/src/services/Connection.d.ts +2 -2
  12. package/dist/esm/common/src/services/Handler.d.ts +8 -9
  13. package/dist/esm/common/src/services/Handler.js +38 -41
  14. package/dist/esm/common/src/util/constants/index.d.ts +0 -1
  15. package/dist/esm/common/src/util/constants/index.js +0 -1
  16. package/dist/esm/common/src/util/helpers.d.ts +10 -3
  17. package/dist/esm/common/src/util/helpers.js +11 -6
  18. package/dist/esm/common/src/util/interfaces.d.ts +56 -21
  19. package/dist/esm/common/src/util/interfaces.js +1 -0
  20. package/dist/esm/common/src/util/logger.js +1 -4
  21. package/dist/esm/common/src/util/webrtc/index.d.ts +2 -7
  22. package/dist/esm/common/src/util/webrtc/index.js +2 -63
  23. package/dist/esm/common/src/webrtc/BaseCall.d.ts +79 -0
  24. package/dist/esm/common/src/webrtc/BaseCall.js +711 -0
  25. package/dist/esm/common/src/webrtc/Call.d.ts +5 -5
  26. package/dist/esm/common/src/webrtc/Call.js +15 -34
  27. package/dist/esm/common/src/webrtc/CantinaAuth.d.ts +14 -9
  28. package/dist/esm/common/src/webrtc/CantinaAuth.js +18 -24
  29. package/dist/esm/common/src/webrtc/LayoutHandler.d.ts +3 -0
  30. package/dist/esm/common/src/webrtc/LayoutHandler.js +36 -0
  31. package/dist/esm/common/src/webrtc/Peer.d.ts +23 -0
  32. package/dist/esm/common/src/webrtc/Peer.js +169 -0
  33. package/dist/esm/common/src/webrtc/VertoHandler.d.ts +11 -2
  34. package/dist/esm/common/src/webrtc/VertoHandler.js +187 -147
  35. package/dist/esm/common/src/webrtc/constants.d.ts +12 -27
  36. package/dist/esm/common/src/webrtc/constants.js +11 -33
  37. package/dist/esm/common/src/webrtc/helpers.d.ts +25 -19
  38. package/dist/esm/common/src/webrtc/helpers.js +190 -162
  39. package/dist/esm/common/src/webrtc/interfaces.d.ts +52 -209
  40. package/dist/esm/common/src/webrtc/interfaces.js +1 -0
  41. package/dist/esm/js/index.d.ts +1 -3
  42. package/dist/esm/js/index.js +2 -2
  43. package/dist/esm/js/src/SignalWire.d.ts +2 -0
  44. package/dist/esm/js/src/SignalWire.js +13 -0
  45. package/dist/esm/js/src/Verto.d.ts +2 -8
  46. package/dist/esm/js/src/Verto.js +14 -50
  47. package/dist/index.min.js +2 -6
  48. package/dist/index.min.js.LICENSE.txt +5 -0
  49. package/package.json +24 -19
  50. package/dist/esm/common/src/webrtc/ChatChannelHandler.d.ts +0 -5
  51. package/dist/esm/common/src/webrtc/ChatChannelHandler.js +0 -22
  52. package/dist/esm/common/src/webrtc/Conference.d.ts +0 -15
  53. package/dist/esm/common/src/webrtc/Conference.js +0 -68
  54. package/dist/esm/common/src/webrtc/ConferenceListChannelHandler.d.ts +0 -5
  55. package/dist/esm/common/src/webrtc/ConferenceListChannelHandler.js +0 -77
  56. package/dist/esm/common/src/webrtc/InfoChannelHandler.d.ts +0 -7
  57. package/dist/esm/common/src/webrtc/InfoChannelHandler.js +0 -85
  58. package/dist/esm/common/src/webrtc/LaChannelHandler.d.ts +0 -5
  59. package/dist/esm/common/src/webrtc/LaChannelHandler.js +0 -58
  60. package/dist/esm/common/src/webrtc/ModChannelHandler.d.ts +0 -71
  61. package/dist/esm/common/src/webrtc/ModChannelHandler.js +0 -267
  62. package/dist/esm/common/src/webrtc/RTCPeer.d.ts +0 -51
  63. package/dist/esm/common/src/webrtc/RTCPeer.js +0 -556
  64. package/dist/esm/common/src/webrtc/WebRTCCall.d.ts +0 -182
  65. package/dist/esm/common/src/webrtc/WebRTCCall.js +0 -784
  66. package/dist/esm/common/src/webrtc/deviceHelpers.d.ts +0 -18
  67. package/dist/esm/common/src/webrtc/deviceHelpers.js +0 -113
  68. package/dist/esm/common/src/webrtc/sdpHelpers.d.ts +0 -3
  69. package/dist/esm/common/src/webrtc/sdpHelpers.js +0 -56
package/README.md CHANGED
@@ -1,7 +1,9 @@
1
- # SignalWire JavaScript SDK
1
+ # SignalWire JavaScript SDK v1
2
2
 
3
3
 
4
- [![Build Status](https://ci.signalwire.com/api/badges/signalwire/signalwire-node/status.svg)](https://ci.signalwire.com/signalwire/signalwire-node) ![NPM](https://img.shields.io/npm/v/@signalwire/js.svg?color=brightgreen)
4
+ [![Build Status](https://ci.signalwire.com/api/badges/signalwire/signalwire-node/status.svg)](https://ci.signalwire.com/signalwire/signalwire-node) ![NPM](https://img.shields.io/npm/v/@signalwire/js/legacy.svg?color=brightgreen)
5
+
6
+ > :warning: For the **latest version** of the JavaScript SDK, please see [signalwire/signalwire-js](https://github.com/signalwire/signalwire-js).
5
7
 
6
8
  The JavaScript SDK transforms your standard browser into a realtime media engine, enabling developers to directly make audio and video calls to phone numbers, SIP endpoints, and other browsers. Using the JavaScript SDK you can add immersive, scalable communication - from video conferences and softphones to click-to-call and mobile gaming - all available right in your own web pages and applications.
7
9
 
@@ -1,27 +1,26 @@
1
1
  import * as log from 'loglevel';
2
2
  import Connection from './services/Connection';
3
3
  import BaseMessage from '../../common/src/messages/BaseMessage';
4
- import { BroadcastParams, ISignalWireOptions, SubscribeParams, IBladeAuthorization } from './util/interfaces';
4
+ import { BroadcastParams, ISignalWireOptions, SubscribeParams, IBladeConnectResult } from './util/interfaces';
5
5
  export default abstract class BaseSession {
6
6
  options: ISignalWireOptions;
7
7
  uuid: string;
8
8
  sessionid: string;
9
- subscriptions: Map<string, boolean>;
9
+ subscriptions: {
10
+ [channel: string]: any;
11
+ };
10
12
  nodeid: string;
11
13
  master_nodeid: string;
14
+ expiresAt: number;
15
+ signature: string;
12
16
  relayProtocol: string;
13
17
  contexts: string[];
14
18
  timeoutErrorCode: number;
15
- authorization: IBladeAuthorization;
16
19
  protected connection: Connection;
17
20
  protected _jwtAuth: boolean;
18
- protected _checkJWTExpirationTimeout: number;
19
- protected _refreshTokenNotificationDiff: number;
20
- protected _expiredDiffSeconds: number;
21
21
  protected _doKeepAlive: boolean;
22
22
  protected _keepAliveTimeout: any;
23
23
  protected _reconnectTimeout: any;
24
- protected _checkTokenExpirationTimeout: any;
25
24
  protected _autoReconnect: boolean;
26
25
  protected _idle: boolean;
27
26
  private _executeQueue;
@@ -29,11 +28,6 @@ export default abstract class BaseSession {
29
28
  constructor(options: ISignalWireOptions);
30
29
  get __logger(): log.Logger;
31
30
  get connected(): boolean;
32
- get signature(): string;
33
- get scopeId(): string;
34
- get resource(): string;
35
- get scopes(): string[];
36
- get expiresAt(): number;
37
31
  get expired(): boolean;
38
32
  get reconnectDelay(): number;
39
33
  execute(msg: BaseMessage): any;
@@ -49,6 +43,7 @@ export default abstract class BaseSession {
49
43
  connect(): Promise<void>;
50
44
  protected _handleLoginError(error: any): void;
51
45
  protected _onSocketOpen(): Promise<void>;
46
+ protected _handleBladeConnectResponse(response: IBladeConnectResult): void;
52
47
  protected _onSocketCloseOrError(event: any): void;
53
48
  protected _onSocketMessage(response: any): void;
54
49
  protected _removeSubscription(protocol: string, channel?: string): void;
@@ -58,7 +53,7 @@ export default abstract class BaseSession {
58
53
  private _detachListeners;
59
54
  private _emptyExecuteQueues;
60
55
  private _closeConnection;
61
- protected _checkTokenExpiration(): void;
56
+ private _checkTokenExpiration;
62
57
  private _keepAlive;
63
58
  static on(eventName: string, callback: any): void;
64
59
  static off(eventName: string): void;
@@ -14,7 +14,7 @@ import Setup from './services/Setup';
14
14
  import { deRegister, register, trigger, deRegisterAll } from './services/Handler';
15
15
  import BroadcastHandler from './services/BroadcastHandler';
16
16
  import { ADD, REMOVE, SwEvent, BladeMethod } from './util/constants';
17
- import { Notification } from './webrtc/constants';
17
+ import { NOTIFICATION_TYPE } from './webrtc/constants';
18
18
  import { Subscription, Connect, Reauthenticate, Ping } from './messages/Blade';
19
19
  import { isFunction, randomInt } from './util/helpers';
20
20
  import { sessionStorage } from './util/storage/';
@@ -24,15 +24,14 @@ export default class BaseSession {
24
24
  this.options = options;
25
25
  this.uuid = uuidv4();
26
26
  this.sessionid = '';
27
- this.subscriptions = new Map();
27
+ this.subscriptions = {};
28
+ this.expiresAt = 0;
29
+ this.signature = null;
28
30
  this.relayProtocol = null;
29
31
  this.contexts = [];
30
32
  this.timeoutErrorCode = -32000;
31
33
  this.connection = null;
32
34
  this._jwtAuth = false;
33
- this._checkJWTExpirationTimeout = 30 * 1000;
34
- this._refreshTokenNotificationDiff = 120;
35
- this._expiredDiffSeconds = 0;
36
35
  this._doKeepAlive = false;
37
36
  this._autoReconnect = true;
38
37
  this._idle = false;
@@ -54,28 +53,8 @@ export default class BaseSession {
54
53
  get connected() {
55
54
  return this.connection && this.connection.connected;
56
55
  }
57
- get signature() {
58
- return this.authorization ? this.authorization.signature : null;
59
- }
60
- get scopeId() {
61
- return this.authorization ? this.authorization.scope_id : null;
62
- }
63
- get resource() {
64
- return this.authorization ? this.authorization.resource : null;
65
- }
66
- get scopes() {
67
- return this.authorization ? this.authorization.scopes : [];
68
- }
69
- get expiresAt() {
70
- return this.authorization ? +this.authorization.expires_at : 0;
71
- }
72
56
  get expired() {
73
- if (this.expiresAt) {
74
- const now = Math.floor(Date.now() / 1000);
75
- const diff = this.expiresAt - now;
76
- return diff <= this._expiredDiffSeconds;
77
- }
78
- return false;
57
+ return this.expiresAt && this.expiresAt <= (Date.now() / 1000);
79
58
  }
80
59
  get reconnectDelay() {
81
60
  return randomInt(6, 2) * 1000;
@@ -131,16 +110,13 @@ export default class BaseSession {
131
110
  disconnect() {
132
111
  return __awaiter(this, void 0, void 0, function* () {
133
112
  clearTimeout(this._reconnectTimeout);
134
- this.subscriptions.clear();
113
+ this.subscriptions = {};
135
114
  this._autoReconnect = false;
136
115
  this.relayProtocol = null;
137
116
  this._closeConnection();
138
117
  yield sessionStorage.removeItem(this.signature);
139
118
  this._executeQueue = [];
140
119
  this._detachListeners();
141
- this.off(SwEvent.Ready);
142
- this.off(SwEvent.Notification);
143
- this.off(SwEvent.Error);
144
120
  });
145
121
  }
146
122
  on(eventName, callback) {
@@ -161,7 +137,8 @@ export default class BaseSession {
161
137
  else {
162
138
  const br = new Reauthenticate(this.options.project, token, this.sessionid);
163
139
  const response = yield this.execute(br);
164
- this.authorization = response.authorization || null;
140
+ const { authorization: { expires_at = null } = {} } = response;
141
+ this.expiresAt = +expires_at || 0;
165
142
  }
166
143
  }
167
144
  catch (error) {
@@ -193,8 +170,9 @@ export default class BaseSession {
193
170
  const response = yield this.execute(bc).catch(this._handleLoginError);
194
171
  if (response) {
195
172
  this._autoReconnect = true;
196
- const { sessionid, nodeid, master_nodeid, authorization } = response;
197
- this.authorization = authorization;
173
+ const { sessionid, nodeid, master_nodeid, authorization: { expires_at = null, signature = null } = {} } = response;
174
+ this.expiresAt = +expires_at || 0;
175
+ this.signature = signature;
198
176
  this.relayProtocol = yield Setup(this);
199
177
  this._checkTokenExpiration();
200
178
  this.sessionid = sessionid;
@@ -203,26 +181,28 @@ export default class BaseSession {
203
181
  this._emptyExecuteQueues();
204
182
  this._pong = null;
205
183
  this._keepAlive();
184
+ this._handleBladeConnectResponse(response);
206
185
  trigger(SwEvent.Ready, this, this.uuid);
207
186
  logger.info('Session Ready!');
208
187
  }
209
188
  });
210
189
  }
190
+ _handleBladeConnectResponse(response) {
191
+ }
211
192
  _onSocketCloseOrError(event) {
212
193
  logger.error(`Socket ${event.type} ${event.message}`);
213
194
  if (this.relayProtocol) {
214
195
  deRegisterAll(this.relayProtocol);
215
196
  }
216
197
  for (const sub in this.subscriptions) {
217
- const protocol = sub.split('|')[0];
218
- deRegisterAll(protocol);
198
+ deRegisterAll(sub);
219
199
  }
220
- this.subscriptions.clear();
200
+ this.subscriptions = {};
221
201
  this.contexts = [];
222
202
  if (this.expired) {
223
203
  this._idle = true;
224
204
  this._autoReconnect = false;
225
- this.authorization = null;
205
+ this.expiresAt = 0;
226
206
  }
227
207
  if (this._autoReconnect) {
228
208
  this._reconnectTimeout = setTimeout(() => this.connect(), this.reconnectDelay);
@@ -244,25 +224,33 @@ export default class BaseSession {
244
224
  return;
245
225
  }
246
226
  if (channel) {
227
+ delete this.subscriptions[protocol][channel];
247
228
  deRegister(protocol, null, channel);
248
229
  }
249
230
  else {
231
+ delete this.subscriptions[protocol];
250
232
  deRegisterAll(protocol);
251
233
  }
252
- this.subscriptions.delete(`${protocol}|${channel}`);
253
234
  }
254
235
  _addSubscription(protocol, handler = null, channel) {
255
236
  if (this._existsSubscription(protocol, channel)) {
256
237
  return;
257
238
  }
239
+ if (!this._existsSubscription(protocol)) {
240
+ this.subscriptions[protocol] = {};
241
+ }
242
+ this.subscriptions[protocol][channel] = {};
258
243
  if (isFunction(handler)) {
259
244
  register(protocol, handler, channel);
260
245
  }
261
- this.subscriptions.set(`${protocol}|${channel}`, true);
262
246
  }
263
247
  _existsSubscription(protocol, channel) {
264
- const sub = `${protocol}|${channel}`;
265
- return this.subscriptions.has(sub);
248
+ if (this.subscriptions.hasOwnProperty(protocol)) {
249
+ if (!channel || (channel && this.subscriptions[protocol].hasOwnProperty(channel))) {
250
+ return true;
251
+ }
252
+ }
253
+ return false;
266
254
  }
267
255
  _attachListeners() {
268
256
  this._detachListeners();
@@ -292,7 +280,6 @@ export default class BaseSession {
292
280
  clearTimeout(this._keepAliveTimeout);
293
281
  if (this.connection) {
294
282
  this.connection.close();
295
- this.connection = null;
296
283
  }
297
284
  }
298
285
  _checkTokenExpiration() {
@@ -300,12 +287,12 @@ export default class BaseSession {
300
287
  return;
301
288
  }
302
289
  const diff = this.expiresAt - (Date.now() / 1000);
303
- if (diff <= this._refreshTokenNotificationDiff) {
304
- trigger(SwEvent.Notification, { type: Notification.RefreshToken, session: this }, this.uuid, false);
290
+ if (diff <= 60) {
291
+ logger.warn('Your JWT is going to expire. You should refresh it to keep the session live.');
292
+ trigger(SwEvent.Notification, { type: NOTIFICATION_TYPE.refreshToken, session: this }, this.uuid, false);
305
293
  }
306
- clearTimeout(this._checkTokenExpirationTimeout);
307
294
  if (!this.expired) {
308
- this._checkTokenExpirationTimeout = setTimeout(this._checkTokenExpiration, this._checkJWTExpirationTimeout);
295
+ setTimeout(this._checkTokenExpiration, 30 * 1000);
309
296
  }
310
297
  }
311
298
  _keepAlive() {
@@ -1,40 +1,28 @@
1
1
  import BaseSession from './BaseSession';
2
- import { IAudioSettings, IVideoSettings, BroadcastParams, SubscribeParams } from './util/interfaces';
3
- import BaseMessage from './messages/BaseMessage';
4
- import WebRTCCall from './webrtc/WebRTCCall';
5
- import { IConferenceInfo, IVertoConferenceListParams } from './webrtc/interfaces';
6
- import Conference from './webrtc/Conference';
2
+ import { ICacheDevices, IAudioSettings, IVideoSettings, BroadcastParams, SubscribeParams, IBladeConnectResult } from './util/interfaces';
3
+ import { IWebRTCCall } from './webrtc/interfaces';
7
4
  export default abstract class BrowserSession extends BaseSession {
8
5
  calls: {
9
- [callId: string]: WebRTCCall;
6
+ [callId: string]: IWebRTCCall;
10
7
  };
11
- conferences: {
12
- [confUuid: string]: Conference;
13
- };
14
- channelToCallIds: Map<string, string[]>;
15
8
  micId: string;
16
9
  micLabel: string;
17
10
  camId: string;
18
11
  camLabel: string;
19
12
  autoRecoverCalls: boolean;
20
- incognito: boolean;
21
- conferenceListBootstrap?: () => void;
22
13
  private _iceServers;
23
14
  private _localElement;
24
15
  private _remoteElement;
25
16
  protected _jwtAuth: boolean;
17
+ protected _devices: ICacheDevices;
26
18
  protected _audioConstraints: boolean | MediaTrackConstraints;
27
19
  protected _videoConstraints: boolean | MediaTrackConstraints;
28
20
  protected _speaker: string;
29
- protected _purgeTimeout: any;
30
- protected _experimental: boolean;
31
- get callIds(): string[];
32
- addChannelCallIdEntry(channel: string, callId: string): void;
33
- removeChannelCallIdEntry(channel: string, callId: string): void;
34
21
  get reconnectDelay(): number;
22
+ protected _handleBladeConnectResponse(response: IBladeConnectResult): void;
35
23
  connect(): Promise<void>;
36
24
  checkPermissions(audio?: boolean, video?: boolean): Promise<boolean>;
37
- purge(): void;
25
+ logout(): void;
38
26
  disconnect(): Promise<void>;
39
27
  speedTest(bytes: number): Promise<unknown>;
40
28
  getDevices(): Promise<MediaDeviceInfo[]>;
@@ -42,10 +30,18 @@ export default abstract class BrowserSession extends BaseSession {
42
30
  getAudioInDevices(): Promise<MediaDeviceInfo[]>;
43
31
  getAudioOutDevices(): Promise<MediaDeviceInfo[]>;
44
32
  validateDeviceId(id: string, label: string, kind: MediaDeviceInfo['kind']): Promise<string>;
45
- validateVideoDevice(id: string, label: string): Promise<string>;
46
- validateAudioInDevice(id: string, label: string): Promise<string>;
47
- validateAudioOutDevice(id: string, label: string): Promise<string>;
33
+ refreshDevices(): Promise<ICacheDevices>;
34
+ get devices(): ICacheDevices;
48
35
  getDeviceResolutions(deviceId: string): Promise<any[]>;
36
+ get videoDevices(): {
37
+ [deviceId: string]: MediaDeviceInfo;
38
+ };
39
+ get audioInDevices(): {
40
+ [deviceId: string]: MediaDeviceInfo;
41
+ };
42
+ get audioOutDevices(): {
43
+ [deviceId: string]: MediaDeviceInfo;
44
+ };
49
45
  get mediaConstraints(): {
50
46
  audio: boolean | MediaTrackConstraints;
51
47
  video: boolean | MediaTrackConstraints;
@@ -64,40 +60,7 @@ export default abstract class BrowserSession extends BaseSession {
64
60
  get localElement(): HTMLMediaElement | string | Function;
65
61
  set remoteElement(tag: HTMLMediaElement | string | Function);
66
62
  get remoteElement(): HTMLMediaElement | string | Function;
67
- vertoBroadcast({ nodeId, channel, data }: BroadcastParams): any;
68
- vertoSubscribe({ nodeId, channels, handler }: SubscribeParams): Promise<any>;
69
- vertoUnsubscribe({ nodeId, channels, handler }: SubscribeParams): Promise<any>;
70
- listConf(): any;
71
- vertoConferenceList(params: IVertoConferenceListParams): Promise<IConferenceInfo[]>;
72
- vertoLayoutList(options?: {
73
- fullList?: boolean;
74
- }): Promise<{
75
- id: string;
76
- label: string;
77
- type: string;
78
- reservationIds: string[];
79
- belongsToAGroup: boolean;
80
- }[]>;
81
- watchVertoConferences: (params: IVertoConferenceListParams) => Promise<IConferenceInfo[]>;
82
- _watchRoomsNotificationHandler: (event: any) => void;
83
- unwatchVertoConferences: () => Promise<void>;
84
- private _detachChannels;
85
- dispatchConferenceUpdate(params: any): void;
86
- _jsApi(params?: {}): any;
87
- _wrapInExecute(message: BaseMessage): BaseMessage;
88
- execute(message: BaseMessage): any;
89
- protected _onSocketOpen(): Promise<void>;
90
- protected _onSocketCloseOrError(event: any): void;
91
- watchVertoConferenceList: () => Promise<void>;
92
- unwatchVertoConferenceList: () => Promise<void>;
93
- vertoSubscribeToConference({ infoChannel, modChannel, laChannel }: {
94
- infoChannel?: string;
95
- modChannel?: string;
96
- laChannel?: string;
97
- }): Promise<void>;
98
- vertoUnsubscribeFromConference({ infoChannel, modChannel, laChannel }: {
99
- infoChannel?: string;
100
- modChannel?: string;
101
- laChannel?: string;
102
- }): Promise<void>;
63
+ vertoBroadcast({ nodeId, channel: eventChannel, data }: BroadcastParams): void;
64
+ vertoSubscribe({ nodeId, channels: eventChannel, handler }: SubscribeParams): Promise<any>;
65
+ vertoUnsubscribe({ nodeId, channels: eventChannel }: SubscribeParams): Promise<any>;
103
66
  }