@signalwire/js 1.3.0-dev.0 → 1.3.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.
- package/README.md +4 -2
- package/dist/esm/common/src/BaseSession.d.ts +8 -13
- package/dist/esm/common/src/BaseSession.js +33 -46
- package/dist/esm/common/src/BrowserSession.d.ts +20 -57
- package/dist/esm/common/src/BrowserSession.js +91 -359
- package/dist/esm/common/src/messages/Verto.d.ts +1 -10
- package/dist/esm/common/src/messages/Verto.js +1 -16
- package/dist/esm/common/src/messages/verto/Login.d.ts +1 -13
- package/dist/esm/common/src/messages/verto/Login.js +2 -5
- package/dist/esm/common/src/services/BroadcastHandler.js +3 -2
- package/dist/esm/common/src/services/Handler.d.ts +8 -9
- package/dist/esm/common/src/services/Handler.js +38 -41
- package/dist/esm/common/src/util/constants/index.d.ts +0 -1
- package/dist/esm/common/src/util/constants/index.js +0 -1
- package/dist/esm/common/src/util/helpers.d.ts +9 -2
- package/dist/esm/common/src/util/helpers.js +11 -6
- package/dist/esm/common/src/util/interfaces.d.ts +55 -20
- package/dist/esm/common/src/util/logger.js +1 -4
- package/dist/esm/common/src/util/webrtc/index.d.ts +1 -6
- package/dist/esm/common/src/util/webrtc/index.js +2 -63
- package/dist/esm/common/src/webrtc/BaseCall.d.ts +76 -0
- package/dist/esm/common/src/webrtc/BaseCall.js +701 -0
- package/dist/esm/common/src/webrtc/Call.d.ts +5 -5
- package/dist/esm/common/src/webrtc/Call.js +15 -34
- package/dist/esm/common/src/webrtc/CantinaAuth.d.ts +13 -8
- package/dist/esm/common/src/webrtc/CantinaAuth.js +18 -24
- package/dist/esm/common/src/webrtc/LayoutHandler.d.ts +3 -0
- package/dist/esm/common/src/webrtc/LayoutHandler.js +36 -0
- package/dist/esm/common/src/webrtc/Peer.d.ts +21 -0
- package/dist/esm/common/src/webrtc/Peer.js +145 -0
- package/dist/esm/common/src/webrtc/VertoHandler.d.ts +11 -2
- package/dist/esm/common/src/webrtc/VertoHandler.js +187 -147
- package/dist/esm/common/src/webrtc/constants.d.ts +12 -28
- package/dist/esm/common/src/webrtc/constants.js +11 -34
- package/dist/esm/common/src/webrtc/helpers.d.ts +20 -18
- package/dist/esm/common/src/webrtc/helpers.js +177 -162
- package/dist/esm/common/src/webrtc/interfaces.d.ts +51 -209
- package/dist/esm/js/index.d.ts +1 -3
- package/dist/esm/js/index.js +1 -2
- package/dist/esm/js/src/SignalWire.d.ts +2 -0
- package/dist/esm/js/src/SignalWire.js +13 -0
- package/dist/esm/js/src/Verto.d.ts +2 -8
- package/dist/esm/js/src/Verto.js +14 -50
- package/dist/index.min.js +2 -2
- package/package.json +13 -14
- package/dist/esm/common/src/webrtc/ChatChannelHandler.d.ts +0 -5
- package/dist/esm/common/src/webrtc/ChatChannelHandler.js +0 -22
- package/dist/esm/common/src/webrtc/Conference.d.ts +0 -15
- package/dist/esm/common/src/webrtc/Conference.js +0 -68
- package/dist/esm/common/src/webrtc/ConferenceListChannelHandler.d.ts +0 -5
- package/dist/esm/common/src/webrtc/ConferenceListChannelHandler.js +0 -77
- package/dist/esm/common/src/webrtc/InfoChannelHandler.d.ts +0 -7
- package/dist/esm/common/src/webrtc/InfoChannelHandler.js +0 -85
- package/dist/esm/common/src/webrtc/LaChannelHandler.d.ts +0 -5
- package/dist/esm/common/src/webrtc/LaChannelHandler.js +0 -58
- package/dist/esm/common/src/webrtc/ModChannelHandler.d.ts +0 -71
- package/dist/esm/common/src/webrtc/ModChannelHandler.js +0 -267
- package/dist/esm/common/src/webrtc/RTCPeer.d.ts +0 -51
- package/dist/esm/common/src/webrtc/RTCPeer.js +0 -556
- package/dist/esm/common/src/webrtc/WebRTCCall.d.ts +0 -182
- package/dist/esm/common/src/webrtc/WebRTCCall.js +0 -784
- package/dist/esm/common/src/webrtc/deviceHelpers.d.ts +0 -18
- package/dist/esm/common/src/webrtc/deviceHelpers.js +0 -113
- package/dist/esm/common/src/webrtc/sdpHelpers.d.ts +0 -3
- package/dist/esm/common/src/webrtc/sdpHelpers.js +0 -56
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BaseCall from './BaseCall';
|
|
2
2
|
import { CallOptions } from './interfaces';
|
|
3
|
-
export default class Call extends
|
|
3
|
+
export default class Call extends BaseCall {
|
|
4
|
+
screenShare: Call;
|
|
4
5
|
private _statsInterval;
|
|
5
|
-
|
|
6
|
+
hangup(params?: any, execute?: boolean): void;
|
|
7
|
+
startScreenShare(opts?: CallOptions): Promise<Call>;
|
|
6
8
|
stopScreenShare(): void;
|
|
7
|
-
addSecondSource(opts?: CallOptions): Promise<WebRTCCall>;
|
|
8
|
-
removeSecondSource(): void;
|
|
9
9
|
setAudioOutDevice(deviceId: string): Promise<boolean>;
|
|
10
10
|
protected _finalize(): void;
|
|
11
11
|
private _stats;
|
|
@@ -8,19 +8,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import logger from '../util/logger';
|
|
11
|
-
import
|
|
11
|
+
import BaseCall from './BaseCall';
|
|
12
12
|
import { getDisplayMedia, setMediaElementSinkId } from '../util/webrtc';
|
|
13
|
-
|
|
14
|
-
export default class Call extends WebRTCCall {
|
|
13
|
+
export default class Call extends BaseCall {
|
|
15
14
|
constructor() {
|
|
16
15
|
super(...arguments);
|
|
17
16
|
this._statsInterval = null;
|
|
18
17
|
}
|
|
18
|
+
hangup(params = {}, execute = true) {
|
|
19
|
+
if (this.screenShare instanceof Call) {
|
|
20
|
+
this.screenShare.hangup(params, execute);
|
|
21
|
+
}
|
|
22
|
+
super.hangup(params, execute);
|
|
23
|
+
}
|
|
19
24
|
startScreenShare(opts) {
|
|
20
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
displayStream.getVideoTracks().forEach(t => {
|
|
26
|
+
const displayStream = yield getDisplayMedia({ video: true });
|
|
27
|
+
displayStream.getTracks().forEach(t => {
|
|
24
28
|
t.addEventListener('ended', () => {
|
|
25
29
|
if (this.screenShare) {
|
|
26
30
|
this.screenShare.hangup();
|
|
@@ -28,8 +32,7 @@ export default class Call extends WebRTCCall {
|
|
|
28
32
|
});
|
|
29
33
|
});
|
|
30
34
|
const { remoteCallerName, remoteCallerNumber, callerName, callerNumber } = this.options;
|
|
31
|
-
const options = Object.assign({ screenShare: true,
|
|
32
|
-
remoteCallerNumber, callerName: `${callerName} (Screen)`, callerNumber: `${callerNumber} (Screen)` }, opts);
|
|
35
|
+
const options = Object.assign({ screenShare: true, localStream: displayStream, destinationNumber: `${this.extension}-screen`, remoteCallerName, remoteCallerNumber: `${remoteCallerNumber}-screen`, callerName: `${callerName} (Screen)`, callerNumber: `${callerNumber} (Screen)` }, opts);
|
|
33
36
|
this.screenShare = new Call(this.session, options);
|
|
34
37
|
this.screenShare.invite();
|
|
35
38
|
return this.screenShare;
|
|
@@ -40,36 +43,14 @@ export default class Call extends WebRTCCall {
|
|
|
40
43
|
this.screenShare.hangup();
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
|
-
addSecondSource(opts) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const { remoteCallerName, remoteCallerNumber, callerName, callerNumber } = this.options;
|
|
46
|
-
const options = Object.assign({ secondSource: true, recoverCall: false, skipLiveArray: true, skipNotifications: true, destinationNumber: this.extension, remoteCallerName,
|
|
47
|
-
remoteCallerNumber, callerName: `${callerName} (Second Source)`, callerNumber: `${callerNumber} (Second Source)`, localStream: null }, opts);
|
|
48
|
-
this.secondSource = new Call(this.session, options);
|
|
49
|
-
this.secondSource.invite();
|
|
50
|
-
return this.secondSource;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
removeSecondSource() {
|
|
54
|
-
if (this.secondSource instanceof Call) {
|
|
55
|
-
this.secondSource.hangup();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
46
|
setAudioOutDevice(deviceId) {
|
|
59
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
48
|
this.options.speakerId = deviceId;
|
|
61
|
-
const { remoteElement, speakerId
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
yield this.audioElements[0].setSinkId(speakerId);
|
|
65
|
-
this._dispatchNotification({ type: Notification.DeviceUpdated });
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
console.error('setAudioOutDevice error', this.audioElements, speakerId);
|
|
69
|
-
}
|
|
70
|
-
return;
|
|
49
|
+
const { remoteElement, speakerId } = this.options;
|
|
50
|
+
if (remoteElement && speakerId) {
|
|
51
|
+
return setMediaElementSinkId(remoteElement, speakerId);
|
|
71
52
|
}
|
|
72
|
-
return
|
|
53
|
+
return false;
|
|
73
54
|
});
|
|
74
55
|
}
|
|
75
56
|
_finalize() {
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import { ICantinaUser } from './interfaces';
|
|
2
|
-
declare type BootstrapResponse = {
|
|
3
|
-
project_id: string;
|
|
4
|
-
};
|
|
1
|
+
import { ICantinaAuthParams, ICantinaUser } from './interfaces';
|
|
5
2
|
declare type RefreshResponse = {
|
|
3
|
+
project: string;
|
|
6
4
|
jwt_token: string;
|
|
7
5
|
};
|
|
6
|
+
declare type CheckInviteTokenResponse = {
|
|
7
|
+
valid: boolean;
|
|
8
|
+
name: string;
|
|
9
|
+
config: object;
|
|
10
|
+
};
|
|
8
11
|
declare class CantinaAuth {
|
|
12
|
+
private params;
|
|
9
13
|
baseUrl: string;
|
|
10
14
|
hostname: string;
|
|
15
|
+
constructor(params?: ICantinaAuthParams);
|
|
11
16
|
private _fetch;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
refresh(
|
|
15
|
-
|
|
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>;
|
|
16
21
|
}
|
|
17
22
|
export default CantinaAuth;
|
|
@@ -16,57 +16,51 @@ const FETCH_OPTIONS = {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
class CantinaAuth {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.
|
|
19
|
+
constructor(params = {}) {
|
|
20
|
+
this.params = params;
|
|
21
|
+
this.baseUrl = 'https://cantina-backend.signalwire.com';
|
|
21
22
|
this._fetch = (url, options) => {
|
|
22
23
|
return fetch(url, options).then((response) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const payload = yield response.json();
|
|
23
25
|
if (response.status >= 200 && response.status < 300) {
|
|
24
|
-
if (response.status === 204) {
|
|
25
|
-
return response;
|
|
26
|
-
}
|
|
27
|
-
const payload = yield response.json();
|
|
28
26
|
return payload;
|
|
29
27
|
}
|
|
30
28
|
else {
|
|
31
29
|
const errorMessage = `HTTP Request failed with status ${response.status}`;
|
|
32
30
|
const error = new Error(errorMessage);
|
|
33
|
-
error.
|
|
31
|
+
error.payload = payload;
|
|
34
32
|
return Promise.reject(error);
|
|
35
33
|
}
|
|
36
34
|
}));
|
|
37
35
|
};
|
|
36
|
+
const { hostname = location.hostname } = params;
|
|
37
|
+
this.hostname = hostname;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
userLogin(username, password) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const response = yield this._fetch(url, Object.assign(Object.assign({}, FETCH_OPTIONS), { method: 'GET' }));
|
|
44
|
-
logger.info('bootstrap response', response);
|
|
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);
|
|
45
43
|
return response;
|
|
46
44
|
});
|
|
47
45
|
}
|
|
48
|
-
|
|
46
|
+
guestLogin(name, email, token) {
|
|
49
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const response = yield this._fetch(`${this.baseUrl}/
|
|
51
|
-
logger.info('
|
|
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);
|
|
52
50
|
return response;
|
|
53
51
|
});
|
|
54
52
|
}
|
|
55
|
-
refresh(
|
|
53
|
+
refresh() {
|
|
56
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const
|
|
58
|
-
if (refreshToken) {
|
|
59
|
-
options.body = JSON.stringify({ refresh_token: refreshToken });
|
|
60
|
-
}
|
|
61
|
-
const response = yield this._fetch(`${this.baseUrl}/api/refresh`, options);
|
|
55
|
+
const response = yield this._fetch(`${this.baseUrl}/refresh`, Object.assign(Object.assign({}, FETCH_OPTIONS), { method: 'PUT', body: JSON.stringify({ hostname: this.hostname }) }));
|
|
62
56
|
logger.info('refresh response', response);
|
|
63
57
|
return response;
|
|
64
58
|
});
|
|
65
59
|
}
|
|
66
|
-
|
|
60
|
+
checkInviteToken(token) {
|
|
67
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const response = yield this._fetch(`${this.baseUrl}/
|
|
69
|
-
logger.info('
|
|
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);
|
|
70
64
|
return response;
|
|
71
65
|
});
|
|
72
66
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { NOTIFICATION_TYPE, ConferenceAction } from './constants';
|
|
2
|
+
import { SwEvent } from '../util/constants';
|
|
3
|
+
import { trigger } from '../services/Handler';
|
|
4
|
+
import { safeParseJson } from '../util/helpers';
|
|
5
|
+
const MCULayoutEventHandler = (session, eventData) => {
|
|
6
|
+
const { contentType, canvasType, callID, canvasInfo = null, currentLayerIdx = -1 } = eventData;
|
|
7
|
+
if (canvasInfo && canvasType !== 'mcu-personal-canvas') {
|
|
8
|
+
delete canvasInfo.memberID;
|
|
9
|
+
}
|
|
10
|
+
const data = {
|
|
11
|
+
type: NOTIFICATION_TYPE.conferenceUpdate,
|
|
12
|
+
call: session.calls[callID],
|
|
13
|
+
canvasInfo: _clearCanvasInfo(canvasInfo),
|
|
14
|
+
currentLayerIdx
|
|
15
|
+
};
|
|
16
|
+
switch (contentType) {
|
|
17
|
+
case 'layer-info': {
|
|
18
|
+
const notification = Object.assign({ action: ConferenceAction.LayerInfo }, data);
|
|
19
|
+
trigger(SwEvent.Notification, notification, session.uuid);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case 'layout-info': {
|
|
23
|
+
const notification = Object.assign({ action: ConferenceAction.LayoutInfo }, data);
|
|
24
|
+
trigger(SwEvent.Notification, notification, session.uuid);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const _clearCanvasInfo = (canvasInfo) => {
|
|
30
|
+
const tmp = JSON.stringify(canvasInfo)
|
|
31
|
+
.replace(/memberID/g, 'participantId')
|
|
32
|
+
.replace(/ID"/g, 'Id"')
|
|
33
|
+
.replace(/POS"/g, 'Pos"');
|
|
34
|
+
return safeParseJson(tmp);
|
|
35
|
+
};
|
|
36
|
+
export { MCULayoutEventHandler };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PeerType } from './constants';
|
|
2
|
+
import { CallOptions } from './interfaces';
|
|
3
|
+
export default class Peer {
|
|
4
|
+
type: PeerType;
|
|
5
|
+
private options;
|
|
6
|
+
instance: RTCPeerConnection;
|
|
7
|
+
onSdpReadyTwice: Function;
|
|
8
|
+
private _constraints;
|
|
9
|
+
private _negotiating;
|
|
10
|
+
constructor(type: PeerType, options: CallOptions);
|
|
11
|
+
startNegotiation(): void;
|
|
12
|
+
private _init;
|
|
13
|
+
private _createOffer;
|
|
14
|
+
private _createAnswer;
|
|
15
|
+
private _setLocalDescription;
|
|
16
|
+
private _sdpReady;
|
|
17
|
+
private _retrieveLocalStream;
|
|
18
|
+
private _isOffer;
|
|
19
|
+
private _isAnswer;
|
|
20
|
+
private _config;
|
|
21
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
import { getUserMedia, getMediaConstraints, sdpStereoHack, sdpBitrateHack } from './helpers';
|
|
12
|
+
import { SwEvent } from '../util/constants';
|
|
13
|
+
import { PeerType } from './constants';
|
|
14
|
+
import { attachMediaStream, muteMediaElement, sdpToJsonHack, RTCPeerConnection, streamIsValid } from '../util/webrtc';
|
|
15
|
+
import { isFunction } from '../util/helpers';
|
|
16
|
+
import { trigger } from '../services/Handler';
|
|
17
|
+
export default class Peer {
|
|
18
|
+
constructor(type, options) {
|
|
19
|
+
this.type = type;
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.onSdpReadyTwice = null;
|
|
22
|
+
this._negotiating = false;
|
|
23
|
+
logger.info('New Peer with type:', this.type, 'Options:', this.options);
|
|
24
|
+
this._constraints = { offerToReceiveAudio: true, offerToReceiveVideo: true };
|
|
25
|
+
this._sdpReady = this._sdpReady.bind(this);
|
|
26
|
+
this._init();
|
|
27
|
+
}
|
|
28
|
+
startNegotiation() {
|
|
29
|
+
this._negotiating = true;
|
|
30
|
+
if (this._isOffer()) {
|
|
31
|
+
this._createOffer();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this._createAnswer();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
_init() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
this.instance = RTCPeerConnection(this._config());
|
|
40
|
+
this.instance.onsignalingstatechange = event => {
|
|
41
|
+
switch (this.instance.signalingState) {
|
|
42
|
+
case 'stable':
|
|
43
|
+
this._negotiating = false;
|
|
44
|
+
break;
|
|
45
|
+
case 'closed':
|
|
46
|
+
this.instance = null;
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
this._negotiating = true;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.instance.onnegotiationneeded = event => {
|
|
53
|
+
if (this._negotiating) {
|
|
54
|
+
logger.debug('Skip twice onnegotiationneeded..');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.startNegotiation();
|
|
58
|
+
};
|
|
59
|
+
this.options.localStream = yield this._retrieveLocalStream()
|
|
60
|
+
.catch(error => {
|
|
61
|
+
trigger(SwEvent.MediaError, error, this.options.id);
|
|
62
|
+
return null;
|
|
63
|
+
});
|
|
64
|
+
const { localElement, localStream = null, screenShare = false } = this.options;
|
|
65
|
+
if (streamIsValid(localStream)) {
|
|
66
|
+
if (typeof this.instance.addTrack === 'function') {
|
|
67
|
+
localStream.getTracks().forEach(t => this.instance.addTrack(t, localStream));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.instance.addStream(localStream);
|
|
71
|
+
}
|
|
72
|
+
if (screenShare !== true) {
|
|
73
|
+
muteMediaElement(localElement);
|
|
74
|
+
attachMediaStream(localElement, localStream);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (localStream === null) {
|
|
78
|
+
this.startNegotiation();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
_createOffer() {
|
|
83
|
+
if (!this._isOffer()) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.instance.createOffer(this._constraints)
|
|
87
|
+
.then(this._setLocalDescription.bind(this))
|
|
88
|
+
.then(this._sdpReady)
|
|
89
|
+
.catch(error => logger.error('Peer _createOffer error:', error));
|
|
90
|
+
}
|
|
91
|
+
_createAnswer() {
|
|
92
|
+
if (!this._isAnswer()) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const { remoteSdp, useStereo } = this.options;
|
|
96
|
+
const sdp = useStereo ? sdpStereoHack(remoteSdp) : remoteSdp;
|
|
97
|
+
const sessionDescr = sdpToJsonHack({ sdp, type: PeerType.Offer });
|
|
98
|
+
this.instance.setRemoteDescription(sessionDescr)
|
|
99
|
+
.then(() => this.instance.createAnswer())
|
|
100
|
+
.then(this._setLocalDescription.bind(this))
|
|
101
|
+
.then(this._sdpReady)
|
|
102
|
+
.catch(error => logger.error('Peer _createAnswer error:', error));
|
|
103
|
+
}
|
|
104
|
+
_setLocalDescription(sessionDescription) {
|
|
105
|
+
const { useStereo, googleMaxBitrate, googleMinBitrate, googleStartBitrate } = this.options;
|
|
106
|
+
if (useStereo) {
|
|
107
|
+
sessionDescription.sdp = sdpStereoHack(sessionDescription.sdp);
|
|
108
|
+
}
|
|
109
|
+
if (googleMaxBitrate && googleMinBitrate && googleStartBitrate) {
|
|
110
|
+
sessionDescription.sdp = sdpBitrateHack(sessionDescription.sdp, googleMaxBitrate, googleMinBitrate, googleStartBitrate);
|
|
111
|
+
}
|
|
112
|
+
return this.instance.setLocalDescription(sessionDescription);
|
|
113
|
+
}
|
|
114
|
+
_sdpReady() {
|
|
115
|
+
if (isFunction(this.onSdpReadyTwice)) {
|
|
116
|
+
this.onSdpReadyTwice(this.instance.localDescription);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
_retrieveLocalStream() {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
if (streamIsValid(this.options.localStream)) {
|
|
122
|
+
return this.options.localStream;
|
|
123
|
+
}
|
|
124
|
+
const constraints = yield getMediaConstraints(this.options);
|
|
125
|
+
return getUserMedia(constraints);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
_isOffer() {
|
|
129
|
+
return this.type === PeerType.Offer;
|
|
130
|
+
}
|
|
131
|
+
_isAnswer() {
|
|
132
|
+
return this.type === PeerType.Answer;
|
|
133
|
+
}
|
|
134
|
+
_config() {
|
|
135
|
+
const { iceServers = [], iceTransportPolicy = 'all' } = this.options;
|
|
136
|
+
const config = {
|
|
137
|
+
iceTransportPolicy,
|
|
138
|
+
sdpSemantics: 'unified-plan',
|
|
139
|
+
bundlePolicy: 'max-compat',
|
|
140
|
+
iceServers,
|
|
141
|
+
};
|
|
142
|
+
logger.info('RTC config', config);
|
|
143
|
+
return config;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
import BrowserSession from '../BrowserSession';
|
|
2
|
-
declare
|
|
3
|
-
|
|
2
|
+
declare class VertoHandler {
|
|
3
|
+
session: BrowserSession;
|
|
4
|
+
nodeId: string;
|
|
5
|
+
constructor(session: BrowserSession);
|
|
6
|
+
private _ack;
|
|
7
|
+
handleMessage(msg: any): Promise<void>;
|
|
8
|
+
private _retrieveCallId;
|
|
9
|
+
private _handlePvtEvent;
|
|
10
|
+
private _handleSessionEvent;
|
|
11
|
+
}
|
|
12
|
+
export default VertoHandler;
|