@signalwire/js 1.2.5-beta.1 → 1.2.8
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.
- package/README.md +4 -2
- package/dist/esm/common/src/BaseSession.d.ts +2 -1
- package/dist/esm/common/src/BaseSession.js +15 -6
- package/dist/esm/common/src/BrowserSession.d.ts +4 -3
- package/dist/esm/common/src/BrowserSession.js +9 -4
- package/dist/esm/common/src/messages/Verto.d.ts +1 -1
- package/dist/esm/common/src/messages/Verto.js +1 -1
- package/dist/esm/common/src/services/Connection.js +3 -3
- package/dist/esm/common/src/util/constants/index.d.ts +0 -44
- package/dist/esm/common/src/util/constants/index.js +0 -49
- package/dist/esm/common/src/util/helpers.d.ts +1 -0
- package/dist/esm/common/src/util/helpers.js +3 -0
- package/dist/esm/common/src/util/interfaces.d.ts +47 -38
- package/dist/esm/common/src/webrtc/BaseCall.d.ts +3 -4
- package/dist/esm/common/src/webrtc/BaseCall.js +2 -2
- package/dist/esm/common/src/webrtc/Call.d.ts +1 -1
- package/dist/esm/common/src/webrtc/CantinaAuth.d.ts +22 -0
- package/dist/esm/common/src/webrtc/CantinaAuth.js +68 -0
- package/dist/esm/common/src/webrtc/LayoutHandler.js +2 -2
- package/dist/esm/common/src/webrtc/Peer.d.ts +2 -2
- package/dist/esm/common/src/webrtc/Peer.js +3 -2
- package/dist/esm/common/src/webrtc/VertoHandler.js +3 -2
- package/dist/esm/common/src/webrtc/constants.d.ts +74 -0
- package/dist/esm/common/src/{util/constants/call.js → webrtc/constants.js} +43 -3
- package/dist/esm/common/src/webrtc/helpers.d.ts +2 -2
- package/dist/esm/common/src/webrtc/helpers.js +9 -15
- package/dist/esm/common/src/webrtc/interfaces.d.ts +87 -0
- package/dist/esm/common/src/webrtc/interfaces.js +0 -0
- package/dist/esm/js/index.d.ts +4 -2
- package/dist/esm/js/index.js +3 -2
- package/dist/esm/js/src/SignalWire.d.ts +1 -1
- package/dist/esm/js/src/Verto.d.ts +3 -1
- package/dist/esm/js/src/Verto.js +5 -0
- package/dist/index.min.js +2 -2
- package/package.json +15 -15
- package/CHANGELOG.md +0 -101
- package/dist/.DS_Store +0 -0
- package/dist/esm/common/src/util/constants/call.d.ts +0 -35
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
# SignalWire JavaScript SDK
|
|
1
|
+
# SignalWire JavaScript SDK v1
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
[](https://ci.signalwire.com/signalwire/signalwire-node) 
|
|
4
|
+
[](https://ci.signalwire.com/signalwire/signalwire-node) 
|
|
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
|
|
|
@@ -15,12 +15,12 @@ export default abstract class BaseSession {
|
|
|
15
15
|
signature: string;
|
|
16
16
|
relayProtocol: string;
|
|
17
17
|
contexts: string[];
|
|
18
|
+
timeoutErrorCode: number;
|
|
18
19
|
protected connection: Connection;
|
|
19
20
|
protected _jwtAuth: boolean;
|
|
20
21
|
protected _doKeepAlive: boolean;
|
|
21
22
|
protected _keepAliveTimeout: any;
|
|
22
23
|
protected _reconnectTimeout: any;
|
|
23
|
-
protected _reconnectDelay: number;
|
|
24
24
|
protected _autoReconnect: boolean;
|
|
25
25
|
protected _idle: boolean;
|
|
26
26
|
private _executeQueue;
|
|
@@ -29,6 +29,7 @@ export default abstract class BaseSession {
|
|
|
29
29
|
get __logger(): log.Logger;
|
|
30
30
|
get connected(): boolean;
|
|
31
31
|
get expired(): boolean;
|
|
32
|
+
get reconnectDelay(): number;
|
|
32
33
|
execute(msg: BaseMessage): any;
|
|
33
34
|
executeRaw(text: string): void;
|
|
34
35
|
validateOptions(): boolean;
|
|
@@ -13,9 +13,10 @@ import Connection from './services/Connection';
|
|
|
13
13
|
import Setup from './services/Setup';
|
|
14
14
|
import { deRegister, register, trigger, deRegisterAll } from './services/Handler';
|
|
15
15
|
import BroadcastHandler from './services/BroadcastHandler';
|
|
16
|
-
import { ADD, REMOVE, SwEvent, BladeMethod
|
|
16
|
+
import { ADD, REMOVE, SwEvent, BladeMethod } from './util/constants';
|
|
17
|
+
import { NOTIFICATION_TYPE } from './webrtc/constants';
|
|
17
18
|
import { Subscription, Connect, Reauthenticate, Ping } from './messages/Blade';
|
|
18
|
-
import { isFunction } from './util/helpers';
|
|
19
|
+
import { isFunction, randomInt } from './util/helpers';
|
|
19
20
|
import { sessionStorage } from './util/storage/';
|
|
20
21
|
const KEEPALIVE_INTERVAL = 10 * 1000;
|
|
21
22
|
export default class BaseSession {
|
|
@@ -28,10 +29,10 @@ export default class BaseSession {
|
|
|
28
29
|
this.signature = null;
|
|
29
30
|
this.relayProtocol = null;
|
|
30
31
|
this.contexts = [];
|
|
32
|
+
this.timeoutErrorCode = -32000;
|
|
31
33
|
this.connection = null;
|
|
32
34
|
this._jwtAuth = false;
|
|
33
35
|
this._doKeepAlive = false;
|
|
34
|
-
this._reconnectDelay = 5000;
|
|
35
36
|
this._autoReconnect = true;
|
|
36
37
|
this._idle = false;
|
|
37
38
|
this._executeQueue = [];
|
|
@@ -55,6 +56,9 @@ export default class BaseSession {
|
|
|
55
56
|
get expired() {
|
|
56
57
|
return this.expiresAt && this.expiresAt <= (Date.now() / 1000);
|
|
57
58
|
}
|
|
59
|
+
get reconnectDelay() {
|
|
60
|
+
return randomInt(6, 2) * 1000;
|
|
61
|
+
}
|
|
58
62
|
execute(msg) {
|
|
59
63
|
if (this._idle) {
|
|
60
64
|
return new Promise(resolve => this._executeQueue.push({ resolve, msg }));
|
|
@@ -65,7 +69,13 @@ export default class BaseSession {
|
|
|
65
69
|
this.connect();
|
|
66
70
|
});
|
|
67
71
|
}
|
|
68
|
-
return this.connection.send(msg)
|
|
72
|
+
return this.connection.send(msg)
|
|
73
|
+
.catch(error => {
|
|
74
|
+
if (error.code && error.code === this.timeoutErrorCode) {
|
|
75
|
+
this._closeConnection();
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
});
|
|
69
79
|
}
|
|
70
80
|
executeRaw(text) {
|
|
71
81
|
if (this._idle) {
|
|
@@ -149,7 +159,6 @@ export default class BaseSession {
|
|
|
149
159
|
});
|
|
150
160
|
}
|
|
151
161
|
_handleLoginError(error) {
|
|
152
|
-
this._autoReconnect = false;
|
|
153
162
|
trigger(SwEvent.Error, error, this.uuid);
|
|
154
163
|
}
|
|
155
164
|
_onSocketOpen() {
|
|
@@ -193,7 +202,7 @@ export default class BaseSession {
|
|
|
193
202
|
this.expiresAt = 0;
|
|
194
203
|
}
|
|
195
204
|
if (this._autoReconnect) {
|
|
196
|
-
this._reconnectTimeout = setTimeout(() => this.connect(), this.
|
|
205
|
+
this._reconnectTimeout = setTimeout(() => this.connect(), this.reconnectDelay);
|
|
197
206
|
}
|
|
198
207
|
}
|
|
199
208
|
_onSocketMessage(response) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import BaseSession from './BaseSession';
|
|
2
|
-
import BaseCall from './webrtc/BaseCall';
|
|
3
2
|
import { ICacheDevices, IAudioSettings, IVideoSettings, BroadcastParams, SubscribeParams } from './util/interfaces';
|
|
3
|
+
import { IWebRTCCall } from './webrtc/interfaces';
|
|
4
4
|
export default abstract class BrowserSession extends BaseSession {
|
|
5
5
|
calls: {
|
|
6
|
-
[callId: string]:
|
|
6
|
+
[callId: string]: IWebRTCCall;
|
|
7
7
|
};
|
|
8
8
|
micId: string;
|
|
9
9
|
micLabel: string;
|
|
@@ -14,11 +14,11 @@ export default abstract class BrowserSession extends BaseSession {
|
|
|
14
14
|
private _localElement;
|
|
15
15
|
private _remoteElement;
|
|
16
16
|
protected _jwtAuth: boolean;
|
|
17
|
-
protected _reconnectDelay: number;
|
|
18
17
|
protected _devices: ICacheDevices;
|
|
19
18
|
protected _audioConstraints: boolean | MediaTrackConstraints;
|
|
20
19
|
protected _videoConstraints: boolean | MediaTrackConstraints;
|
|
21
20
|
protected _speaker: string;
|
|
21
|
+
get reconnectDelay(): number;
|
|
22
22
|
connect(): Promise<void>;
|
|
23
23
|
checkPermissions(audio?: boolean, video?: boolean): Promise<boolean>;
|
|
24
24
|
logout(): void;
|
|
@@ -28,6 +28,7 @@ export default abstract class BrowserSession extends BaseSession {
|
|
|
28
28
|
getVideoDevices(): Promise<MediaDeviceInfo[]>;
|
|
29
29
|
getAudioInDevices(): Promise<MediaDeviceInfo[]>;
|
|
30
30
|
getAudioOutDevices(): Promise<MediaDeviceInfo[]>;
|
|
31
|
+
validateDeviceId(id: string, label: string, kind: MediaDeviceInfo['kind']): Promise<string>;
|
|
31
32
|
refreshDevices(): Promise<ICacheDevices>;
|
|
32
33
|
get devices(): ICacheDevices;
|
|
33
34
|
getDeviceResolutions(deviceId: string): Promise<any[]>;
|
|
@@ -21,9 +21,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
import logger from './util/logger';
|
|
22
22
|
import BaseSession from './BaseSession';
|
|
23
23
|
import { registerOnce, trigger } from './services/Handler';
|
|
24
|
-
import { SwEvent, SESSION_ID
|
|
25
|
-
import { State } from './
|
|
26
|
-
import { getDevices, scanResolutions, removeUnsupportedConstraints, checkDeviceIdConstraints, destructSubscribeResponse, getUserMedia } from './webrtc/helpers';
|
|
24
|
+
import { SwEvent, SESSION_ID } from './util/constants';
|
|
25
|
+
import { State, DeviceType } from './webrtc/constants';
|
|
26
|
+
import { getDevices, scanResolutions, removeUnsupportedConstraints, checkDeviceIdConstraints, destructSubscribeResponse, getUserMedia, assureDeviceId } from './webrtc/helpers';
|
|
27
27
|
import { findElementByType } from './util/helpers';
|
|
28
28
|
import { Unsubscribe, Subscribe, Broadcast } from './messages/Verto';
|
|
29
29
|
import { localStorage } from './util/storage/';
|
|
@@ -37,12 +37,14 @@ export default class BrowserSession extends BaseSession {
|
|
|
37
37
|
this._localElement = null;
|
|
38
38
|
this._remoteElement = null;
|
|
39
39
|
this._jwtAuth = true;
|
|
40
|
-
this._reconnectDelay = 1000;
|
|
41
40
|
this._devices = {};
|
|
42
41
|
this._audioConstraints = true;
|
|
43
42
|
this._videoConstraints = false;
|
|
44
43
|
this._speaker = null;
|
|
45
44
|
}
|
|
45
|
+
get reconnectDelay() {
|
|
46
|
+
return 1000;
|
|
47
|
+
}
|
|
46
48
|
connect() {
|
|
47
49
|
const _super = Object.create(null, {
|
|
48
50
|
connect: { get: () => super.connect }
|
|
@@ -125,6 +127,9 @@ export default class BrowserSession extends BaseSession {
|
|
|
125
127
|
return [];
|
|
126
128
|
});
|
|
127
129
|
}
|
|
130
|
+
validateDeviceId(id, label, kind) {
|
|
131
|
+
return assureDeviceId(id, label, kind);
|
|
132
|
+
}
|
|
128
133
|
refreshDevices() {
|
|
129
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
135
|
logger.warn('This method has been deprecated. Use getDevices() instead.');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BaseRequest from './verto/BaseRequest';
|
|
2
2
|
import { Login } from './verto/Login';
|
|
3
3
|
import { Result } from './verto/Result';
|
|
4
|
-
import { VertoMethod } from '../
|
|
4
|
+
import { VertoMethod } from '../webrtc/constants';
|
|
5
5
|
declare class Invite extends BaseRequest {
|
|
6
6
|
toString(): VertoMethod;
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BaseRequest from './verto/BaseRequest';
|
|
2
2
|
import { Login } from './verto/Login';
|
|
3
3
|
import { Result } from './verto/Result';
|
|
4
|
-
import { VertoMethod } from '../
|
|
4
|
+
import { VertoMethod } from '../webrtc/constants';
|
|
5
5
|
class Invite extends BaseRequest {
|
|
6
6
|
toString() {
|
|
7
7
|
return VertoMethod.Invite;
|
|
@@ -13,7 +13,7 @@ const WS_STATE = {
|
|
|
13
13
|
CLOSING: 2,
|
|
14
14
|
CLOSED: 3
|
|
15
15
|
};
|
|
16
|
-
const
|
|
16
|
+
const TIMEOUT_MS = 10 * 1000;
|
|
17
17
|
export default class Connection {
|
|
18
18
|
constructor(session) {
|
|
19
19
|
this.session = session;
|
|
@@ -94,9 +94,9 @@ export default class Connection {
|
|
|
94
94
|
}
|
|
95
95
|
_setTimer(id) {
|
|
96
96
|
this._timers[id] = setTimeout(() => {
|
|
97
|
-
trigger(id, { error: { code:
|
|
97
|
+
trigger(id, { error: { code: this.session.timeoutErrorCode, message: 'Timeout' } });
|
|
98
98
|
this._unsetTimer(id);
|
|
99
|
-
},
|
|
99
|
+
}, TIMEOUT_MS);
|
|
100
100
|
}
|
|
101
101
|
_handleStringResponse(response) {
|
|
102
102
|
if (/^#SP/.test(response)) {
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export declare enum Netcast {
|
|
2
|
-
ProtocolProviderAdd = "protocol.provider.add",
|
|
3
|
-
ProtocolProviderRemove = "protocol.provider.remove"
|
|
4
|
-
}
|
|
5
1
|
export declare const STORAGE_PREFIX = "@signalwire:";
|
|
6
2
|
export declare const ADD = "add";
|
|
7
3
|
export declare const REMOVE = "remove";
|
|
@@ -19,47 +15,7 @@ export declare enum SwEvent {
|
|
|
19
15
|
Calls = "signalwire.calls",
|
|
20
16
|
MediaError = "signalwire.rtc.mediaError"
|
|
21
17
|
}
|
|
22
|
-
export declare enum PeerType {
|
|
23
|
-
Offer = "offer",
|
|
24
|
-
Answer = "answer"
|
|
25
|
-
}
|
|
26
|
-
export declare enum Direction {
|
|
27
|
-
Inbound = "inbound",
|
|
28
|
-
Outbound = "outbound"
|
|
29
|
-
}
|
|
30
|
-
export declare enum VertoMethod {
|
|
31
|
-
Invite = "verto.invite",
|
|
32
|
-
Attach = "verto.attach",
|
|
33
|
-
Answer = "verto.answer",
|
|
34
|
-
Info = "verto.info",
|
|
35
|
-
Display = "verto.display",
|
|
36
|
-
Media = "verto.media",
|
|
37
|
-
Event = "verto.event",
|
|
38
|
-
Bye = "verto.bye",
|
|
39
|
-
Punt = "verto.punt",
|
|
40
|
-
Broadcast = "verto.broadcast",
|
|
41
|
-
Subscribe = "verto.subscribe",
|
|
42
|
-
Unsubscribe = "verto.unsubscribe",
|
|
43
|
-
ClientReady = "verto.clientReady",
|
|
44
|
-
Modify = "verto.modify"
|
|
45
|
-
}
|
|
46
|
-
export declare const NOTIFICATION_TYPE: {
|
|
47
|
-
generic: string;
|
|
48
|
-
[VertoMethod.Display]: string;
|
|
49
|
-
[VertoMethod.Attach]: string;
|
|
50
|
-
conferenceUpdate: string;
|
|
51
|
-
callUpdate: string;
|
|
52
|
-
vertoClientReady: string;
|
|
53
|
-
userMediaError: string;
|
|
54
|
-
refreshToken: string;
|
|
55
|
-
};
|
|
56
18
|
export declare enum BladeMethod {
|
|
57
|
-
Netcast = "blade.netcast",
|
|
58
19
|
Broadcast = "blade.broadcast",
|
|
59
20
|
Disconnect = "blade.disconnect"
|
|
60
21
|
}
|
|
61
|
-
export declare enum DeviceType {
|
|
62
|
-
Video = "videoinput",
|
|
63
|
-
AudioIn = "audioinput",
|
|
64
|
-
AudioOut = "audiooutput"
|
|
65
|
-
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
export var Netcast;
|
|
2
|
-
(function (Netcast) {
|
|
3
|
-
Netcast["ProtocolProviderAdd"] = "protocol.provider.add";
|
|
4
|
-
Netcast["ProtocolProviderRemove"] = "protocol.provider.remove";
|
|
5
|
-
})(Netcast || (Netcast = {}));
|
|
6
1
|
export const STORAGE_PREFIX = '@signalwire:';
|
|
7
2
|
export const ADD = 'add';
|
|
8
3
|
export const REMOVE = 'remove';
|
|
@@ -21,52 +16,8 @@ export var SwEvent;
|
|
|
21
16
|
SwEvent["Calls"] = "signalwire.calls";
|
|
22
17
|
SwEvent["MediaError"] = "signalwire.rtc.mediaError";
|
|
23
18
|
})(SwEvent || (SwEvent = {}));
|
|
24
|
-
export var PeerType;
|
|
25
|
-
(function (PeerType) {
|
|
26
|
-
PeerType["Offer"] = "offer";
|
|
27
|
-
PeerType["Answer"] = "answer";
|
|
28
|
-
})(PeerType || (PeerType = {}));
|
|
29
|
-
export var Direction;
|
|
30
|
-
(function (Direction) {
|
|
31
|
-
Direction["Inbound"] = "inbound";
|
|
32
|
-
Direction["Outbound"] = "outbound";
|
|
33
|
-
})(Direction || (Direction = {}));
|
|
34
|
-
export var VertoMethod;
|
|
35
|
-
(function (VertoMethod) {
|
|
36
|
-
VertoMethod["Invite"] = "verto.invite";
|
|
37
|
-
VertoMethod["Attach"] = "verto.attach";
|
|
38
|
-
VertoMethod["Answer"] = "verto.answer";
|
|
39
|
-
VertoMethod["Info"] = "verto.info";
|
|
40
|
-
VertoMethod["Display"] = "verto.display";
|
|
41
|
-
VertoMethod["Media"] = "verto.media";
|
|
42
|
-
VertoMethod["Event"] = "verto.event";
|
|
43
|
-
VertoMethod["Bye"] = "verto.bye";
|
|
44
|
-
VertoMethod["Punt"] = "verto.punt";
|
|
45
|
-
VertoMethod["Broadcast"] = "verto.broadcast";
|
|
46
|
-
VertoMethod["Subscribe"] = "verto.subscribe";
|
|
47
|
-
VertoMethod["Unsubscribe"] = "verto.unsubscribe";
|
|
48
|
-
VertoMethod["ClientReady"] = "verto.clientReady";
|
|
49
|
-
VertoMethod["Modify"] = "verto.modify";
|
|
50
|
-
})(VertoMethod || (VertoMethod = {}));
|
|
51
|
-
export const NOTIFICATION_TYPE = {
|
|
52
|
-
generic: 'event',
|
|
53
|
-
[VertoMethod.Display]: 'participantData',
|
|
54
|
-
[VertoMethod.Attach]: 'participantData',
|
|
55
|
-
conferenceUpdate: 'conferenceUpdate',
|
|
56
|
-
callUpdate: 'callUpdate',
|
|
57
|
-
vertoClientReady: 'vertoClientReady',
|
|
58
|
-
userMediaError: 'userMediaError',
|
|
59
|
-
refreshToken: 'refreshToken',
|
|
60
|
-
};
|
|
61
19
|
export var BladeMethod;
|
|
62
20
|
(function (BladeMethod) {
|
|
63
|
-
BladeMethod["Netcast"] = "blade.netcast";
|
|
64
21
|
BladeMethod["Broadcast"] = "blade.broadcast";
|
|
65
22
|
BladeMethod["Disconnect"] = "blade.disconnect";
|
|
66
23
|
})(BladeMethod || (BladeMethod = {}));
|
|
67
|
-
export var DeviceType;
|
|
68
|
-
(function (DeviceType) {
|
|
69
|
-
DeviceType["Video"] = "videoinput";
|
|
70
|
-
DeviceType["AudioIn"] = "audioinput";
|
|
71
|
-
DeviceType["AudioOut"] = "audiooutput";
|
|
72
|
-
})(DeviceType || (DeviceType = {}));
|
|
@@ -7,6 +7,7 @@ declare type TBladeVersion = {
|
|
|
7
7
|
minor: number;
|
|
8
8
|
revision: number;
|
|
9
9
|
};
|
|
10
|
+
declare type SipCodec = 'PCMU' | 'PCMA' | 'OPUS' | 'G729' | 'G722' | 'VP8' | 'H264';
|
|
10
11
|
export interface ISubscription {
|
|
11
12
|
channel: string;
|
|
12
13
|
protocol: string;
|
|
@@ -76,35 +77,6 @@ export interface ISignalWireOptions {
|
|
|
76
77
|
password?: string;
|
|
77
78
|
userVariables?: Object;
|
|
78
79
|
}
|
|
79
|
-
export interface CallOptions {
|
|
80
|
-
destinationNumber: string;
|
|
81
|
-
remoteCallerName: string;
|
|
82
|
-
remoteCallerNumber: string;
|
|
83
|
-
callerName: string;
|
|
84
|
-
callerNumber: string;
|
|
85
|
-
id?: string;
|
|
86
|
-
remoteSdp?: string;
|
|
87
|
-
localStream?: MediaStream;
|
|
88
|
-
remoteStream?: MediaStream;
|
|
89
|
-
localElement?: HTMLMediaElement | string | Function;
|
|
90
|
-
remoteElement?: HTMLMediaElement | string | Function;
|
|
91
|
-
iceServers?: RTCIceServer[];
|
|
92
|
-
audio?: boolean | MediaTrackConstraints;
|
|
93
|
-
video?: boolean | MediaTrackConstraints;
|
|
94
|
-
attach?: boolean;
|
|
95
|
-
useStereo?: boolean;
|
|
96
|
-
micId?: string;
|
|
97
|
-
micLabel?: string;
|
|
98
|
-
camId?: string;
|
|
99
|
-
camLabel?: string;
|
|
100
|
-
speakerId?: string;
|
|
101
|
-
userVariables?: Object;
|
|
102
|
-
screenShare?: boolean;
|
|
103
|
-
onNotification?: Function;
|
|
104
|
-
googleMaxBitrate?: number;
|
|
105
|
-
googleMinBitrate?: number;
|
|
106
|
-
googleStartBitrate?: number;
|
|
107
|
-
}
|
|
108
80
|
export interface SubscribeParams {
|
|
109
81
|
channels?: string[];
|
|
110
82
|
protocol?: string;
|
|
@@ -129,12 +101,12 @@ export interface ICacheDevices {
|
|
|
129
101
|
};
|
|
130
102
|
}
|
|
131
103
|
export interface IAudioSettings extends MediaTrackConstraints {
|
|
132
|
-
micId
|
|
133
|
-
micLabel
|
|
104
|
+
micId?: string;
|
|
105
|
+
micLabel?: string;
|
|
134
106
|
}
|
|
135
107
|
export interface IVideoSettings extends MediaTrackConstraints {
|
|
136
|
-
camId
|
|
137
|
-
camLabel
|
|
108
|
+
camId?: string;
|
|
109
|
+
camLabel?: string;
|
|
138
110
|
}
|
|
139
111
|
export interface ICall {
|
|
140
112
|
id: string;
|
|
@@ -201,33 +173,65 @@ export interface ICall {
|
|
|
201
173
|
sendDigits: Function;
|
|
202
174
|
sendDigitsAsync: Function;
|
|
203
175
|
}
|
|
204
|
-
export interface
|
|
205
|
-
type:
|
|
176
|
+
export interface CallingPhoneDevice {
|
|
177
|
+
type: 'phone';
|
|
206
178
|
params: {
|
|
207
179
|
from_number: string;
|
|
208
180
|
to_number: string;
|
|
209
|
-
timeout
|
|
181
|
+
timeout?: number;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export interface SipHeader {
|
|
185
|
+
name: string;
|
|
186
|
+
value: string;
|
|
187
|
+
}
|
|
188
|
+
export interface CallingSipDevice {
|
|
189
|
+
type: 'sip';
|
|
190
|
+
params: {
|
|
191
|
+
from: string;
|
|
192
|
+
to: string;
|
|
193
|
+
headers?: SipHeader[];
|
|
194
|
+
timeout?: number;
|
|
195
|
+
codecs?: SipCodec[];
|
|
196
|
+
webrtc_media?: boolean;
|
|
210
197
|
};
|
|
211
198
|
}
|
|
199
|
+
export declare type ICallDevice = CallingPhoneDevice | CallingSipDevice;
|
|
212
200
|
export interface ICallPeer {
|
|
213
201
|
call_id: string;
|
|
214
202
|
node_id: string;
|
|
215
203
|
device?: ICallDevice;
|
|
216
204
|
}
|
|
217
205
|
export interface ICallOptions {
|
|
206
|
+
region?: string;
|
|
218
207
|
device?: ICallDevice;
|
|
208
|
+
devices?: DeepArray<ICallDevice>;
|
|
219
209
|
peer?: ICallPeer;
|
|
220
210
|
node_id?: string;
|
|
221
211
|
call_id?: string;
|
|
222
212
|
call_state?: string;
|
|
223
213
|
context?: string;
|
|
224
214
|
}
|
|
225
|
-
export interface
|
|
226
|
-
type:
|
|
215
|
+
export interface MakePhoneCallParams {
|
|
216
|
+
type: 'phone';
|
|
227
217
|
from?: string;
|
|
228
218
|
to: string;
|
|
229
219
|
timeout?: number;
|
|
230
220
|
}
|
|
221
|
+
export interface MakeSipCallParams {
|
|
222
|
+
type: 'sip';
|
|
223
|
+
from: string;
|
|
224
|
+
to: string;
|
|
225
|
+
timeout?: number;
|
|
226
|
+
headers?: SipHeader[];
|
|
227
|
+
codecs?: SipCodec[];
|
|
228
|
+
webrtc_media?: boolean;
|
|
229
|
+
}
|
|
230
|
+
export interface IDialCallParams {
|
|
231
|
+
region?: string;
|
|
232
|
+
devices: DeepArray<IMakeCallParams>;
|
|
233
|
+
}
|
|
234
|
+
export declare type IMakeCallParams = MakePhoneCallParams | MakeSipCallParams;
|
|
231
235
|
export interface StringTMap<T> {
|
|
232
236
|
[key: string]: T;
|
|
233
237
|
}
|
|
@@ -414,4 +418,9 @@ export interface IMessageOptions {
|
|
|
414
418
|
segments: number;
|
|
415
419
|
reason?: string;
|
|
416
420
|
}
|
|
421
|
+
export interface DialPayload {
|
|
422
|
+
tag: string;
|
|
423
|
+
devices: DeepArray<ICallDevice>;
|
|
424
|
+
region?: string;
|
|
425
|
+
}
|
|
417
426
|
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import BrowserSession from '../BrowserSession';
|
|
2
2
|
import Peer from './Peer';
|
|
3
|
-
import { Direction } from '
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export default abstract class BaseCall {
|
|
3
|
+
import { State, Direction } from './constants';
|
|
4
|
+
import { CallOptions, IWebRTCCall } from './interfaces';
|
|
5
|
+
export default abstract class BaseCall implements IWebRTCCall {
|
|
7
6
|
protected session: BrowserSession;
|
|
8
7
|
id: string;
|
|
9
8
|
state: string;
|
|
@@ -11,8 +11,8 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
11
11
|
import logger from '../util/logger';
|
|
12
12
|
import { Invite, Answer, Attach, Bye, Modify, Info } from '../messages/Verto';
|
|
13
13
|
import Peer from './Peer';
|
|
14
|
-
import {
|
|
15
|
-
import { State, DEFAULT_CALL_OPTIONS, ConferenceAction, Role } from '
|
|
14
|
+
import { SwEvent } from '../util/constants';
|
|
15
|
+
import { State, DEFAULT_CALL_OPTIONS, ConferenceAction, Role, PeerType, VertoMethod, NOTIFICATION_TYPE, Direction } from './constants';
|
|
16
16
|
import { trigger, register, deRegister } from '../services/Handler';
|
|
17
17
|
import { sdpStereoHack, sdpMediaOrderHack, checkSubscribeResponse, enableAudioTracks, disableAudioTracks, toggleAudioTracks, enableVideoTracks, disableVideoTracks, toggleVideoTracks } from './helpers';
|
|
18
18
|
import { objEmpty, mutateLiveArrayData, isFunction } from '../util/helpers';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ICantinaAuthParams, ICantinaUser } from './interfaces';
|
|
2
|
+
declare type RefreshResponse = {
|
|
3
|
+
project: string;
|
|
4
|
+
jwt_token: string;
|
|
5
|
+
};
|
|
6
|
+
declare type CheckInviteTokenResponse = {
|
|
7
|
+
valid: boolean;
|
|
8
|
+
name: string;
|
|
9
|
+
config: object;
|
|
10
|
+
};
|
|
11
|
+
declare class CantinaAuth {
|
|
12
|
+
private params;
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
hostname: string;
|
|
15
|
+
constructor(params?: ICantinaAuthParams);
|
|
16
|
+
private _fetch;
|
|
17
|
+
userLogin(username: string, password: string): Promise<ICantinaUser>;
|
|
18
|
+
guestLogin(name: string, email: string, token: string): Promise<ICantinaUser>;
|
|
19
|
+
refresh(): Promise<RefreshResponse>;
|
|
20
|
+
checkInviteToken(token: string): Promise<CheckInviteTokenResponse>;
|
|
21
|
+
}
|
|
22
|
+
export default CantinaAuth;
|
|
@@ -0,0 +1,68 @@
|
|
|
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 logger from '../util/logger';
|
|
11
|
+
const FETCH_OPTIONS = {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
credentials: 'include',
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json'
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
class CantinaAuth {
|
|
19
|
+
constructor(params = {}) {
|
|
20
|
+
this.params = params;
|
|
21
|
+
this.baseUrl = 'https://cantina-backend.signalwire.com';
|
|
22
|
+
this._fetch = (url, options) => {
|
|
23
|
+
return fetch(url, options).then((response) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const payload = yield response.json();
|
|
25
|
+
if (response.status >= 200 && response.status < 300) {
|
|
26
|
+
return payload;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const errorMessage = `HTTP Request failed with status ${response.status}`;
|
|
30
|
+
const error = new Error(errorMessage);
|
|
31
|
+
error.payload = payload;
|
|
32
|
+
return Promise.reject(error);
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
const { hostname = location.hostname } = params;
|
|
37
|
+
this.hostname = hostname;
|
|
38
|
+
}
|
|
39
|
+
userLogin(username, password) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const response = yield this._fetch(`${this.baseUrl}/login/user`, Object.assign(Object.assign({}, FETCH_OPTIONS), { body: JSON.stringify({ username, password, hostname: this.hostname }) }));
|
|
42
|
+
logger.info('userLogin response', response);
|
|
43
|
+
return response;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
guestLogin(name, email, token) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const response = yield this._fetch(`${this.baseUrl}/login/guest`, Object.assign(Object.assign({}, FETCH_OPTIONS), { body: JSON.stringify({ name, email, token, hostname: this.hostname }) }));
|
|
49
|
+
logger.info('guestLogin response', response);
|
|
50
|
+
return response;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
refresh() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const response = yield this._fetch(`${this.baseUrl}/refresh`, Object.assign(Object.assign({}, FETCH_OPTIONS), { method: 'PUT', body: JSON.stringify({ hostname: this.hostname }) }));
|
|
56
|
+
logger.info('refresh response', response);
|
|
57
|
+
return response;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
checkInviteToken(token) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const response = yield this._fetch(`${this.baseUrl}/check-token`, Object.assign(Object.assign({}, FETCH_OPTIONS), { body: JSON.stringify({ token, hostname: this.hostname }) }));
|
|
63
|
+
logger.info('checkInviteToken response', response);
|
|
64
|
+
return response;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export default CantinaAuth;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NOTIFICATION_TYPE, ConferenceAction } from './constants';
|
|
2
|
+
import { SwEvent } from '../util/constants';
|
|
2
3
|
import { trigger } from '../services/Handler';
|
|
3
|
-
import { ConferenceAction } from '../util/constants/call';
|
|
4
4
|
import { safeParseJson } from '../util/helpers';
|
|
5
5
|
const MCULayoutEventHandler = (session, eventData) => {
|
|
6
6
|
const { contentType, canvasType, callID, canvasInfo = null, currentLayerIdx = -1 } = eventData;
|
|
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import logger from '../util/logger';
|
|
11
11
|
import { getUserMedia, getMediaConstraints, sdpStereoHack, sdpBitrateHack } from './helpers';
|
|
12
|
-
import {
|
|
12
|
+
import { SwEvent } from '../util/constants';
|
|
13
|
+
import { PeerType } from './constants';
|
|
13
14
|
import { attachMediaStream, muteMediaElement, sdpToJsonHack, RTCPeerConnection, streamIsValid } from '../util/webrtc';
|
|
14
15
|
import { isFunction } from '../util/helpers';
|
|
15
16
|
import { trigger } from '../services/Handler';
|
|
@@ -132,7 +133,7 @@ export default class Peer {
|
|
|
132
133
|
}
|
|
133
134
|
_config() {
|
|
134
135
|
const { iceServers = [] } = this.options;
|
|
135
|
-
const config = { sdpSemantics: 'plan
|
|
136
|
+
const config = { sdpSemantics: 'unified-plan', bundlePolicy: 'max-compat', iceServers };
|
|
136
137
|
logger.info('RTC config', config);
|
|
137
138
|
return config;
|
|
138
139
|
}
|