@wazo/sdk 0.37.41 → 0.38.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/dist/wazo-sdk.js +3 -3
- package/esm/__tests__/api-client.test.js +45 -22
- package/esm/__tests__/web-rtc-client.test.js +49 -24
- package/esm/api/agentd.js +12 -7
- package/esm/api/amid.js +12 -7
- package/esm/api/application.js +12 -7
- package/esm/api/auth.js +16 -8
- package/esm/api/call-logd.js +12 -7
- package/esm/api/calld.js +12 -7
- package/esm/api/chatd.js +12 -7
- package/esm/api/confd.js +12 -7
- package/esm/api/ctid-ng.js +14 -7
- package/esm/api/dird.js +12 -7
- package/esm/api/webhookd.js +12 -7
- package/esm/api-client.js +45 -22
- package/esm/checker/Checker.js +50 -25
- package/esm/checker/checks/aor.js +45 -22
- package/esm/checker/checks/api.js +45 -22
- package/esm/checker/checks/index.js +50 -25
- package/esm/checker/checks/wazo-websocket.js +13 -8
- package/esm/checker/checks/webrtc-transport.js +49 -24
- package/esm/checker/checks/webrtc.js +49 -24
- package/esm/domain/AdHocAPIConference.js +54 -23
- package/esm/domain/Features.js +54 -23
- package/esm/domain/Phone/CTIPhone.js +54 -23
- package/esm/domain/Phone/WebRTCPhone.js +14 -7
- package/esm/index.js +233 -25
- package/esm/lib/WazoSessionDescriptionHandler.js +12 -7
- package/esm/service/CallApi.js +54 -23
- package/esm/service/IssueReporter.js +12 -7
- package/esm/service/__tests__/IssueReporter.test.js +18 -7
- package/esm/service/getApiClient.js +63 -24
- package/esm/simple/Auth.js +233 -25
- package/esm/simple/Configuration.js +233 -25
- package/esm/simple/Directory.js +54 -23
- package/esm/simple/Phone.js +233 -25
- package/esm/simple/Softphone.js +148 -0
- package/esm/simple/Websocket.js +13 -8
- package/esm/simple/index.js +233 -25
- package/esm/simple/room/LocalParticipant.js +233 -25
- package/esm/simple/room/Participant.js +233 -25
- package/esm/simple/room/RemoteParticipant.js +233 -25
- package/esm/simple/room/Room.js +233 -25
- package/esm/simple/room/SipRoom.js +233 -25
- package/esm/simple/room/Stream.js +233 -25
- package/esm/simple/room/__tests__/RemoteParticipant.test.js +233 -25
- package/esm/simple/utils.js +233 -25
- package/esm/utils/__tests__/api-requester.test.js +12 -7
- package/esm/utils/api-requester.js +12 -7
- package/esm/web-rtc-client.js +49 -24
- package/esm/websocket-client.js +13 -8
- package/lib/__tests__/api-client.test.js +45 -22
- package/lib/__tests__/web-rtc-client.test.js +49 -24
- package/lib/api/agentd.js +12 -7
- package/lib/api/amid.js +12 -7
- package/lib/api/application.js +12 -7
- package/lib/api/auth.js +16 -8
- package/lib/api/call-logd.js +12 -7
- package/lib/api/calld.js +12 -7
- package/lib/api/chatd.js +12 -7
- package/lib/api/confd.js +12 -7
- package/lib/api/ctid-ng.js +14 -7
- package/lib/api/dird.js +12 -7
- package/lib/api/webhookd.js +12 -7
- package/lib/api-client.js +45 -22
- package/lib/checker/Checker.js +50 -25
- package/lib/checker/checks/aor.js +45 -22
- package/lib/checker/checks/api.js +45 -22
- package/lib/checker/checks/index.js +50 -25
- package/lib/checker/checks/wazo-websocket.js +13 -8
- package/lib/checker/checks/webrtc-transport.js +49 -24
- package/lib/checker/checks/webrtc.js +49 -24
- package/lib/domain/AdHocAPIConference.js +54 -23
- package/lib/domain/Features.js +54 -23
- package/lib/domain/Phone/CTIPhone.js +54 -23
- package/lib/domain/Phone/WebRTCPhone.js +14 -7
- package/lib/index.js +233 -25
- package/lib/lib/WazoSessionDescriptionHandler.js +12 -7
- package/lib/service/CallApi.js +54 -23
- package/lib/service/IssueReporter.js +12 -7
- package/lib/service/__tests__/IssueReporter.test.js +18 -7
- package/lib/service/getApiClient.js +64 -23
- package/lib/simple/Auth.js +233 -25
- package/lib/simple/Configuration.js +233 -25
- package/lib/simple/Directory.js +54 -23
- package/lib/simple/Phone.js +233 -25
- package/lib/simple/Softphone.js +150 -0
- package/lib/simple/Websocket.js +13 -8
- package/lib/simple/index.js +233 -25
- package/lib/simple/room/LocalParticipant.js +233 -25
- package/lib/simple/room/Participant.js +233 -25
- package/lib/simple/room/RemoteParticipant.js +233 -25
- package/lib/simple/room/Room.js +233 -25
- package/lib/simple/room/SipRoom.js +233 -25
- package/lib/simple/room/Stream.js +233 -25
- package/lib/simple/room/__tests__/RemoteParticipant.test.js +233 -25
- package/lib/simple/utils.js +233 -25
- package/lib/utils/__tests__/api-requester.test.js +12 -7
- package/lib/utils/api-requester.js +12 -7
- package/lib/web-rtc-client.js +49 -24
- package/lib/websocket-client.js +13 -8
- package/package.json +1 -1
- package/src/api/auth.js +4 -1
- package/src/api-client.js +26 -13
- package/src/service/IssueReporter.js +12 -7
- package/src/service/__tests__/IssueReporter.test.js +6 -0
- package/src/service/getApiClient.js +19 -1
- package/src/simple/Auth.js +21 -0
- package/src/simple/Softphone.js +148 -0
- package/src/simple/index.js +2 -0
- package/src/web-rtc-client.js +4 -2
- package/src/websocket-client.js +1 -1
package/esm/simple/Phone.js
CHANGED
|
@@ -1029,13 +1029,9 @@ class IssueReporter {
|
|
|
1029
1029
|
|
|
1030
1030
|
setTimeout(() => {
|
|
1031
1031
|
if (isArray) {
|
|
1032
|
-
payload = payload.map(message =>
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
});
|
|
1036
|
-
} else {
|
|
1037
|
-
// $FlowFixMe
|
|
1038
|
-
payload._retry = retry + 1;
|
|
1032
|
+
payload = payload.map(message => this._writeRetryCount(message, retry + 1));
|
|
1033
|
+
} else if (payload && typeof payload === 'object') {
|
|
1034
|
+
payload = this._writeRetryCount(payload, retry + 1);
|
|
1039
1035
|
}
|
|
1040
1036
|
|
|
1041
1037
|
this._sendDebugToGrafana(payload, retry + 1);
|
|
@@ -1043,6 +1039,15 @@ class IssueReporter {
|
|
|
1043
1039
|
});
|
|
1044
1040
|
}
|
|
1045
1041
|
|
|
1042
|
+
_writeRetryCount(message , count ) {
|
|
1043
|
+
if (message && typeof message === 'object') {
|
|
1044
|
+
// $FlowFixMe
|
|
1045
|
+
message._retry = count;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
return message;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1046
1051
|
_isLevelAbove(level1 , level2 ) {
|
|
1047
1052
|
const index1 = LOG_LEVELS.indexOf(level1);
|
|
1048
1053
|
const index2 = LOG_LEVELS.indexOf(level2);
|
|
@@ -2868,9 +2873,12 @@ var authMethods = (client , baseUrl ) => ({
|
|
|
2868
2873
|
expiration: expiration || DETAULT_EXPIRATION,
|
|
2869
2874
|
refresh_token: refreshToken,
|
|
2870
2875
|
client_id: client.clientId,
|
|
2871
|
-
tenant_id: tenantId,
|
|
2872
2876
|
};
|
|
2873
2877
|
|
|
2878
|
+
if (tenantId) {
|
|
2879
|
+
body.tenant_id = tenantId;
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2874
2882
|
const headers = {
|
|
2875
2883
|
'Content-Type': 'application/json',
|
|
2876
2884
|
...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
|
|
@@ -5415,6 +5423,7 @@ class ApiClient {
|
|
|
5415
5423
|
|
|
5416
5424
|
|
|
5417
5425
|
|
|
5426
|
+
|
|
5418
5427
|
|
|
5419
5428
|
|
|
5420
5429
|
|
|
@@ -5467,23 +5476,31 @@ class ApiClient {
|
|
|
5467
5476
|
return null;
|
|
5468
5477
|
}
|
|
5469
5478
|
|
|
5470
|
-
|
|
5471
|
-
this.refreshToken
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5479
|
+
try {
|
|
5480
|
+
const session = await this.auth.refreshToken(
|
|
5481
|
+
this.refreshToken,
|
|
5482
|
+
this.refreshBackend,
|
|
5483
|
+
this.refreshExpiration,
|
|
5484
|
+
this.isMobile,
|
|
5485
|
+
this.refreshTenantId,
|
|
5486
|
+
);
|
|
5477
5487
|
|
|
5478
|
-
|
|
5488
|
+
logger$a.info('token refreshed', { token: session.token });
|
|
5479
5489
|
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5490
|
+
if (this.onRefreshToken) {
|
|
5491
|
+
this.onRefreshToken(session.token, session);
|
|
5492
|
+
}
|
|
5483
5493
|
|
|
5484
|
-
|
|
5494
|
+
this.setToken(session.token);
|
|
5495
|
+
|
|
5496
|
+
return session.token;
|
|
5497
|
+
} catch (error) {
|
|
5498
|
+
logger$a.error('token refresh, error', error);
|
|
5485
5499
|
|
|
5486
|
-
|
|
5500
|
+
if (this.onRefreshTokenError) {
|
|
5501
|
+
this.onRefreshTokenError(error);
|
|
5502
|
+
}
|
|
5503
|
+
}
|
|
5487
5504
|
}
|
|
5488
5505
|
|
|
5489
5506
|
setToken(token ) {
|
|
@@ -5506,6 +5523,10 @@ class ApiClient {
|
|
|
5506
5523
|
this.onRefreshToken = onRefreshToken;
|
|
5507
5524
|
}
|
|
5508
5525
|
|
|
5526
|
+
setOnRefreshTokenError(callback ) {
|
|
5527
|
+
this.onRefreshTokenError = callback;
|
|
5528
|
+
}
|
|
5529
|
+
|
|
5509
5530
|
setRefreshExpiration(refreshExpiration ) {
|
|
5510
5531
|
this.refreshExpiration = refreshExpiration;
|
|
5511
5532
|
}
|
|
@@ -5541,7 +5562,9 @@ global.wazoClients = global.wazoClients || {};
|
|
|
5541
5562
|
global.wazoClientId = global.wazoClientId || {};
|
|
5542
5563
|
global.wazoClientToken = global.wazoClientToken || {};
|
|
5543
5564
|
global.wazoRefreshToken = global.wazoRefreshToken || {};
|
|
5565
|
+
global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
|
|
5544
5566
|
global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
|
|
5567
|
+
global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
|
|
5545
5568
|
global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
|
|
5546
5569
|
global.wazoRefreshBackend = global.wazoRefreshBackend || {};
|
|
5547
5570
|
global.wazoIsMobile = global.wazoIsMobile || {};
|
|
@@ -5563,10 +5586,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
|
|
|
5563
5586
|
global.wazoRefreshToken[forServer] = newRefreshToken;
|
|
5564
5587
|
};
|
|
5565
5588
|
|
|
5589
|
+
const setRefreshTenantId = (refreshTenantId , forServer = null) => {
|
|
5590
|
+
global.wazoRefreshTenantId[forServer] = refreshTenantId;
|
|
5591
|
+
};
|
|
5592
|
+
|
|
5566
5593
|
const setOnRefreshToken = (onRefreshToken , forServer = null) => {
|
|
5567
5594
|
global.wazoOnRefreshToken[forServer] = onRefreshToken;
|
|
5568
5595
|
};
|
|
5569
5596
|
|
|
5597
|
+
const setOnRefreshTokenError = (callback , forServer = null) => {
|
|
5598
|
+
global.wazoOnRefreshTokenError[forServer] = callback;
|
|
5599
|
+
};
|
|
5600
|
+
|
|
5570
5601
|
const setRefreshExpiration = (refreshExpiration , forServer = null) => {
|
|
5571
5602
|
global.wazoRefreshExpiration[forServer] = refreshExpiration;
|
|
5572
5603
|
};
|
|
@@ -5585,12 +5616,20 @@ const fillClient = (apiClient ) => {
|
|
|
5585
5616
|
|
|
5586
5617
|
apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
|
|
5587
5618
|
|
|
5619
|
+
apiClient.setRefreshTenantId(
|
|
5620
|
+
global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
|
|
5621
|
+
);
|
|
5622
|
+
|
|
5588
5623
|
apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
|
|
5589
5624
|
|
|
5590
5625
|
apiClient.setOnRefreshToken(
|
|
5591
5626
|
global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
|
|
5592
5627
|
);
|
|
5593
5628
|
|
|
5629
|
+
apiClient.setOnRefreshTokenError(
|
|
5630
|
+
global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
|
|
5631
|
+
);
|
|
5632
|
+
|
|
5594
5633
|
apiClient.setRefreshExpiration(
|
|
5595
5634
|
global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
|
|
5596
5635
|
);
|
|
@@ -5604,7 +5643,7 @@ const fillClient = (apiClient ) => {
|
|
|
5604
5643
|
return apiClient;
|
|
5605
5644
|
};
|
|
5606
5645
|
|
|
5607
|
-
var getApiClient = (forServer
|
|
5646
|
+
var getApiClient = (forServer = null) => {
|
|
5608
5647
|
const server = forServer || global.wazoCurrentServer || '';
|
|
5609
5648
|
if (server in global.wazoClients) {
|
|
5610
5649
|
return fillClient(global.wazoClients[server]);
|
|
@@ -7140,8 +7179,10 @@ class WebRTCClient extends Emitter {
|
|
|
7140
7179
|
conference: isConference,
|
|
7141
7180
|
};
|
|
7142
7181
|
|
|
7143
|
-
// Avoid sdh to
|
|
7144
|
-
session.sessionDescriptionHandler
|
|
7182
|
+
// Avoid sdh to create a new stream
|
|
7183
|
+
if (session.sessionDescriptionHandler) {
|
|
7184
|
+
session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
|
|
7185
|
+
}
|
|
7145
7186
|
|
|
7146
7187
|
// Send re-INVITE
|
|
7147
7188
|
return session.invite(options);
|
|
@@ -10402,6 +10443,7 @@ class Auth {
|
|
|
10402
10443
|
|
|
10403
10444
|
|
|
10404
10445
|
|
|
10446
|
+
|
|
10405
10447
|
|
|
10406
10448
|
|
|
10407
10449
|
|
|
@@ -10439,6 +10481,14 @@ class Auth {
|
|
|
10439
10481
|
this.onRefreshTokenCallback(token, session);
|
|
10440
10482
|
}
|
|
10441
10483
|
});
|
|
10484
|
+
|
|
10485
|
+
setOnRefreshTokenError(error => {
|
|
10486
|
+
logger$7.error('on refresh token error', error);
|
|
10487
|
+
|
|
10488
|
+
if (this.onRefreshTokenCallbackError) {
|
|
10489
|
+
this.onRefreshTokenCallbackError(error);
|
|
10490
|
+
}
|
|
10491
|
+
});
|
|
10442
10492
|
}
|
|
10443
10493
|
|
|
10444
10494
|
setFetchOptions(options ) {
|
|
@@ -10527,6 +10577,10 @@ class Auth {
|
|
|
10527
10577
|
this.onRefreshTokenCallback = callback;
|
|
10528
10578
|
}
|
|
10529
10579
|
|
|
10580
|
+
setOnRefreshTokenError(callback ) {
|
|
10581
|
+
this.onRefreshTokenCallbackError = callback;
|
|
10582
|
+
}
|
|
10583
|
+
|
|
10530
10584
|
checkAuthorizations(session , authorizationName ) {
|
|
10531
10585
|
if (!authorizationName) {
|
|
10532
10586
|
return;
|
|
@@ -10559,6 +10613,12 @@ class Auth {
|
|
|
10559
10613
|
setRefreshToken(refreshToken);
|
|
10560
10614
|
}
|
|
10561
10615
|
|
|
10616
|
+
setRefreshTenantId(refreshTenantId ) {
|
|
10617
|
+
setRefreshTenantId(refreshTenantId);
|
|
10618
|
+
|
|
10619
|
+
getApiClient().setRefreshTenantId(refreshTenantId);
|
|
10620
|
+
}
|
|
10621
|
+
|
|
10562
10622
|
forceRefreshToken() {
|
|
10563
10623
|
getApiClient().forceRefreshToken();
|
|
10564
10624
|
}
|
|
@@ -11016,7 +11076,7 @@ class WebSocketClient extends Emitter {
|
|
|
11016
11076
|
this.close();
|
|
11017
11077
|
}
|
|
11018
11078
|
const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
|
|
11019
|
-
logger$6.
|
|
11079
|
+
logger$6.info('Wazo WS url computed to reconnect', { url });
|
|
11020
11080
|
|
|
11021
11081
|
return url;
|
|
11022
11082
|
}
|
|
@@ -13499,6 +13559,153 @@ class Checker {
|
|
|
13499
13559
|
}
|
|
13500
13560
|
}
|
|
13501
13561
|
|
|
13562
|
+
//
|
|
13563
|
+
/* eslint-disable no-unused-vars */
|
|
13564
|
+
/* global window, document */
|
|
13565
|
+
const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
|
|
13566
|
+
const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
|
|
13567
|
+
const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
|
|
13568
|
+
const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
|
|
13569
|
+
const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
|
|
13570
|
+
|
|
13571
|
+
class Softphone {
|
|
13572
|
+
url = 'https://softphone.wazo.io';
|
|
13573
|
+
width = 500;
|
|
13574
|
+
height = 600;
|
|
13575
|
+
displayed = false;
|
|
13576
|
+
iframe = null;
|
|
13577
|
+
|
|
13578
|
+
onLinkEnabled(link ) {}
|
|
13579
|
+
|
|
13580
|
+
onCallMade(call ) {}
|
|
13581
|
+
onCallIncoming(call ) {}
|
|
13582
|
+
onCallEnded(call , card , direction , fromExtension ) {}
|
|
13583
|
+
onAuthenticated(session ) {}
|
|
13584
|
+
|
|
13585
|
+
init(url , width , height ) {
|
|
13586
|
+
if (url) {
|
|
13587
|
+
this.url = url;
|
|
13588
|
+
}
|
|
13589
|
+
if (width) {
|
|
13590
|
+
this.width = width;
|
|
13591
|
+
}
|
|
13592
|
+
if (height) {
|
|
13593
|
+
this.height = height;
|
|
13594
|
+
}
|
|
13595
|
+
|
|
13596
|
+
window.addEventListener('message', this._onMessage.bind(this), false);
|
|
13597
|
+
|
|
13598
|
+
this._createIframe();
|
|
13599
|
+
}
|
|
13600
|
+
|
|
13601
|
+
parseLinks() {
|
|
13602
|
+
const links = this._getLinks();
|
|
13603
|
+
|
|
13604
|
+
links.forEach(link => {
|
|
13605
|
+
link.setAttribute('data-wazo-parsed', true);
|
|
13606
|
+
link.addEventListener('click', this._onLinkClick.bind(this));
|
|
13607
|
+
this.onLinkEnabled(link);
|
|
13608
|
+
});
|
|
13609
|
+
}
|
|
13610
|
+
|
|
13611
|
+
makeCall(number ) {
|
|
13612
|
+
this.displaySoftphone();
|
|
13613
|
+
|
|
13614
|
+
if (this.iframe) {
|
|
13615
|
+
this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
|
|
13616
|
+
}
|
|
13617
|
+
}
|
|
13618
|
+
|
|
13619
|
+
toggleSoftphoneDisplay() {
|
|
13620
|
+
if (this.displayed) {
|
|
13621
|
+
this.hideSoftphone();
|
|
13622
|
+
} else {
|
|
13623
|
+
this.displaySoftphone();
|
|
13624
|
+
}
|
|
13625
|
+
|
|
13626
|
+
this.displayed = !this.displayed;
|
|
13627
|
+
}
|
|
13628
|
+
|
|
13629
|
+
displaySoftphone() {
|
|
13630
|
+
if (!this.iframe) {
|
|
13631
|
+
this._createIframe();
|
|
13632
|
+
}
|
|
13633
|
+
|
|
13634
|
+
if (this.iframe) {
|
|
13635
|
+
this.iframe.style.display = 'block';
|
|
13636
|
+
}
|
|
13637
|
+
}
|
|
13638
|
+
|
|
13639
|
+
hideSoftphone() {
|
|
13640
|
+
if (this.iframe) {
|
|
13641
|
+
this.iframe.style.display = 'none';
|
|
13642
|
+
}
|
|
13643
|
+
}
|
|
13644
|
+
|
|
13645
|
+
_createIframe() {
|
|
13646
|
+
this.iframe = document.createElement('iframe');
|
|
13647
|
+
// $FlowFixMe
|
|
13648
|
+
this.iframe.width = this.width;
|
|
13649
|
+
// $FlowFixMe
|
|
13650
|
+
this.iframe.height = this.height;
|
|
13651
|
+
// $FlowFixMe
|
|
13652
|
+
this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
|
|
13653
|
+
this.iframe.style.position = 'absolute';
|
|
13654
|
+
this.iframe.style.left = '0';
|
|
13655
|
+
this.iframe.style.bottom = '0';
|
|
13656
|
+
this.iframe.style.border = '1px solid #aaa';
|
|
13657
|
+
this.iframe.src = this.url;
|
|
13658
|
+
this.iframe.style.display = 'none';
|
|
13659
|
+
this.iframe.id = 'wazo-softphone';
|
|
13660
|
+
|
|
13661
|
+
// $FlowFixMe
|
|
13662
|
+
document.body.appendChild(this.iframe);
|
|
13663
|
+
}
|
|
13664
|
+
|
|
13665
|
+
_getLinks() {
|
|
13666
|
+
return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
|
|
13667
|
+
.filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
|
|
13668
|
+
}
|
|
13669
|
+
|
|
13670
|
+
_onLinkClick(e ) {
|
|
13671
|
+
e.preventDefault();
|
|
13672
|
+
const number = e.target.href.split(':')[1];
|
|
13673
|
+
|
|
13674
|
+
this.makeCall(number);
|
|
13675
|
+
}
|
|
13676
|
+
|
|
13677
|
+
_onAuthenticated() {
|
|
13678
|
+
this.parseLinks();
|
|
13679
|
+
}
|
|
13680
|
+
|
|
13681
|
+
_onMessage(event ) {
|
|
13682
|
+
if (!event.data) {
|
|
13683
|
+
return;
|
|
13684
|
+
}
|
|
13685
|
+
|
|
13686
|
+
switch (event.data.type) {
|
|
13687
|
+
case SDK_ON_CALL_MADE:
|
|
13688
|
+
this.onCallMade(event.data.callSession);
|
|
13689
|
+
break;
|
|
13690
|
+
case SDK_CALL_ENDED: {
|
|
13691
|
+
const { callSession, content, direction, userExtension } = event.data;
|
|
13692
|
+
this.onCallEnded(callSession, content, direction, userExtension);
|
|
13693
|
+
break;
|
|
13694
|
+
}
|
|
13695
|
+
case SDK_CALL_INCOMING:
|
|
13696
|
+
this.onCallIncoming(event.data.callSession);
|
|
13697
|
+
break;
|
|
13698
|
+
case SDK_AUTHENTICATED:
|
|
13699
|
+
// $FlowFixMe
|
|
13700
|
+
this._onAuthenticated(event.data.session);
|
|
13701
|
+
this.onAuthenticated(event.data.session);
|
|
13702
|
+
break;
|
|
13703
|
+
}
|
|
13704
|
+
}
|
|
13705
|
+
}
|
|
13706
|
+
|
|
13707
|
+
var Softphone$1 = new Softphone();
|
|
13708
|
+
|
|
13502
13709
|
/* global window */
|
|
13503
13710
|
|
|
13504
13711
|
const Wazo = {
|
|
@@ -13519,6 +13726,7 @@ const Wazo = {
|
|
|
13519
13726
|
loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
|
|
13520
13727
|
Features: Features$1,
|
|
13521
13728
|
Checker,
|
|
13729
|
+
Softphone: Softphone$1,
|
|
13522
13730
|
|
|
13523
13731
|
// Domain
|
|
13524
13732
|
domain: {
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
//
|
|
2
|
+
/* eslint-disable no-unused-vars */
|
|
3
|
+
/* global window, document */
|
|
4
|
+
const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
|
|
5
|
+
const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
|
|
6
|
+
const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
|
|
7
|
+
const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
|
|
8
|
+
const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
|
|
9
|
+
|
|
10
|
+
class Softphone {
|
|
11
|
+
url = 'https://softphone.wazo.io';
|
|
12
|
+
width = 500;
|
|
13
|
+
height = 600;
|
|
14
|
+
displayed = false;
|
|
15
|
+
iframe = null;
|
|
16
|
+
|
|
17
|
+
onLinkEnabled(link ) {}
|
|
18
|
+
|
|
19
|
+
onCallMade(call ) {}
|
|
20
|
+
onCallIncoming(call ) {}
|
|
21
|
+
onCallEnded(call , card , direction , fromExtension ) {}
|
|
22
|
+
onAuthenticated(session ) {}
|
|
23
|
+
|
|
24
|
+
init(url , width , height ) {
|
|
25
|
+
if (url) {
|
|
26
|
+
this.url = url;
|
|
27
|
+
}
|
|
28
|
+
if (width) {
|
|
29
|
+
this.width = width;
|
|
30
|
+
}
|
|
31
|
+
if (height) {
|
|
32
|
+
this.height = height;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
window.addEventListener('message', this._onMessage.bind(this), false);
|
|
36
|
+
|
|
37
|
+
this._createIframe();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
parseLinks() {
|
|
41
|
+
const links = this._getLinks();
|
|
42
|
+
|
|
43
|
+
links.forEach(link => {
|
|
44
|
+
link.setAttribute('data-wazo-parsed', true);
|
|
45
|
+
link.addEventListener('click', this._onLinkClick.bind(this));
|
|
46
|
+
this.onLinkEnabled(link);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
makeCall(number ) {
|
|
51
|
+
this.displaySoftphone();
|
|
52
|
+
|
|
53
|
+
if (this.iframe) {
|
|
54
|
+
this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
toggleSoftphoneDisplay() {
|
|
59
|
+
if (this.displayed) {
|
|
60
|
+
this.hideSoftphone();
|
|
61
|
+
} else {
|
|
62
|
+
this.displaySoftphone();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.displayed = !this.displayed;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
displaySoftphone() {
|
|
69
|
+
if (!this.iframe) {
|
|
70
|
+
this._createIframe();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (this.iframe) {
|
|
74
|
+
this.iframe.style.display = 'block';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
hideSoftphone() {
|
|
79
|
+
if (this.iframe) {
|
|
80
|
+
this.iframe.style.display = 'none';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
_createIframe() {
|
|
85
|
+
this.iframe = document.createElement('iframe');
|
|
86
|
+
// $FlowFixMe
|
|
87
|
+
this.iframe.width = this.width;
|
|
88
|
+
// $FlowFixMe
|
|
89
|
+
this.iframe.height = this.height;
|
|
90
|
+
// $FlowFixMe
|
|
91
|
+
this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
|
|
92
|
+
this.iframe.style.position = 'absolute';
|
|
93
|
+
this.iframe.style.left = '0';
|
|
94
|
+
this.iframe.style.bottom = '0';
|
|
95
|
+
this.iframe.style.border = '1px solid #aaa';
|
|
96
|
+
this.iframe.src = this.url;
|
|
97
|
+
this.iframe.style.display = 'none';
|
|
98
|
+
this.iframe.id = 'wazo-softphone';
|
|
99
|
+
|
|
100
|
+
// $FlowFixMe
|
|
101
|
+
document.body.appendChild(this.iframe);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_getLinks() {
|
|
105
|
+
return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
|
|
106
|
+
.filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_onLinkClick(e ) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
const number = e.target.href.split(':')[1];
|
|
112
|
+
|
|
113
|
+
this.makeCall(number);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_onAuthenticated() {
|
|
117
|
+
this.parseLinks();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
_onMessage(event ) {
|
|
121
|
+
if (!event.data) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
switch (event.data.type) {
|
|
126
|
+
case SDK_ON_CALL_MADE:
|
|
127
|
+
this.onCallMade(event.data.callSession);
|
|
128
|
+
break;
|
|
129
|
+
case SDK_CALL_ENDED: {
|
|
130
|
+
const { callSession, content, direction, userExtension } = event.data;
|
|
131
|
+
this.onCallEnded(callSession, content, direction, userExtension);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case SDK_CALL_INCOMING:
|
|
135
|
+
this.onCallIncoming(event.data.callSession);
|
|
136
|
+
break;
|
|
137
|
+
case SDK_AUTHENTICATED:
|
|
138
|
+
// $FlowFixMe
|
|
139
|
+
this._onAuthenticated(event.data.session);
|
|
140
|
+
this.onAuthenticated(event.data.session);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
var Softphone$1 = new Softphone();
|
|
147
|
+
|
|
148
|
+
export default Softphone$1;
|
package/esm/simple/Websocket.js
CHANGED
|
@@ -387,13 +387,9 @@ class IssueReporter {
|
|
|
387
387
|
|
|
388
388
|
setTimeout(() => {
|
|
389
389
|
if (isArray) {
|
|
390
|
-
payload = payload.map(message =>
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
});
|
|
394
|
-
} else {
|
|
395
|
-
// $FlowFixMe
|
|
396
|
-
payload._retry = retry + 1;
|
|
390
|
+
payload = payload.map(message => this._writeRetryCount(message, retry + 1));
|
|
391
|
+
} else if (payload && typeof payload === 'object') {
|
|
392
|
+
payload = this._writeRetryCount(payload, retry + 1);
|
|
397
393
|
}
|
|
398
394
|
|
|
399
395
|
this._sendDebugToGrafana(payload, retry + 1);
|
|
@@ -401,6 +397,15 @@ class IssueReporter {
|
|
|
401
397
|
});
|
|
402
398
|
}
|
|
403
399
|
|
|
400
|
+
_writeRetryCount(message , count ) {
|
|
401
|
+
if (message && typeof message === 'object') {
|
|
402
|
+
// $FlowFixMe
|
|
403
|
+
message._retry = count;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return message;
|
|
407
|
+
}
|
|
408
|
+
|
|
404
409
|
_isLevelAbove(level1 , level2 ) {
|
|
405
410
|
const index1 = LOG_LEVELS.indexOf(level1);
|
|
406
411
|
const index2 = LOG_LEVELS.indexOf(level2);
|
|
@@ -861,7 +866,7 @@ class WebSocketClient extends Emitter {
|
|
|
861
866
|
this.close();
|
|
862
867
|
}
|
|
863
868
|
const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
|
|
864
|
-
logger$1.
|
|
869
|
+
logger$1.info('Wazo WS url computed to reconnect', { url });
|
|
865
870
|
|
|
866
871
|
return url;
|
|
867
872
|
}
|