@wazo/sdk 0.37.15 → 0.37.19

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 (114) hide show
  1. package/dist/wazo-sdk.js +3 -3
  2. package/esm/__tests__/api-client.test.js +9 -5
  3. package/esm/__tests__/web-rtc-client.test.js +117 -23
  4. package/esm/api/agentd.js +1 -1
  5. package/esm/api/amid.js +1 -1
  6. package/esm/api/application.js +1 -1
  7. package/esm/api/auth.js +1 -1
  8. package/esm/api/call-logd.js +3 -3
  9. package/esm/api/calld.js +1 -1
  10. package/esm/api/chatd.js +1 -1
  11. package/esm/api/confd.js +7 -3
  12. package/esm/api/ctid-ng.js +1 -1
  13. package/esm/api/dird.js +1 -1
  14. package/esm/api/webhookd.js +1 -1
  15. package/esm/api-client.js +9 -5
  16. package/esm/checker/Checker.js +117 -23
  17. package/esm/checker/checks/aor.js +9 -5
  18. package/esm/checker/checks/api.js +9 -5
  19. package/esm/checker/checks/index.js +117 -23
  20. package/esm/checker/checks/wazo-websocket.js +1 -1
  21. package/esm/checker/checks/webrtc-transport.js +117 -23
  22. package/esm/checker/checks/webrtc.js +117 -23
  23. package/esm/domain/AdHocAPIConference.js +9 -5
  24. package/esm/domain/CallLog.js +2 -2
  25. package/esm/domain/Features.js +9 -5
  26. package/esm/domain/Meeting.js +6 -2
  27. package/esm/domain/Phone/CTIPhone.js +9 -5
  28. package/esm/domain/Phone/WebRTCPhone.js +9 -2
  29. package/esm/domain/Recording.js +1 -1
  30. package/esm/domain/__tests__/CallLog.test.js +2 -2
  31. package/esm/index.js +125 -23
  32. package/esm/lib/WazoSessionDescriptionHandler.js +1 -1
  33. package/esm/service/CallApi.js +9 -5
  34. package/esm/service/IssueReporter.js +1 -1
  35. package/esm/service/__tests__/IssueReporter.test.js +1 -1
  36. package/esm/service/getApiClient.js +9 -5
  37. package/esm/simple/Auth.js +125 -23
  38. package/esm/simple/Configuration.js +125 -23
  39. package/esm/simple/Directory.js +9 -5
  40. package/esm/simple/Phone.js +125 -23
  41. package/esm/simple/Websocket.js +1 -1
  42. package/esm/simple/index.js +125 -23
  43. package/esm/simple/room/LocalParticipant.js +125 -23
  44. package/esm/simple/room/Participant.js +125 -23
  45. package/esm/simple/room/RemoteParticipant.js +125 -23
  46. package/esm/simple/room/Room.js +125 -23
  47. package/esm/simple/room/SipRoom.js +125 -23
  48. package/esm/simple/room/Stream.js +125 -23
  49. package/esm/simple/room/__tests__/RemoteParticipant.test.js +125 -23
  50. package/esm/simple/utils.js +125 -23
  51. package/esm/utils/__tests__/api-requester.test.js +1 -1
  52. package/esm/utils/api-requester.js +1 -1
  53. package/esm/web-rtc-client.js +117 -23
  54. package/esm/websocket-client.js +1 -1
  55. package/lib/__tests__/api-client.test.js +9 -5
  56. package/lib/__tests__/web-rtc-client.test.js +117 -23
  57. package/lib/api/agentd.js +1 -1
  58. package/lib/api/amid.js +1 -1
  59. package/lib/api/application.js +1 -1
  60. package/lib/api/auth.js +1 -1
  61. package/lib/api/call-logd.js +3 -3
  62. package/lib/api/calld.js +1 -1
  63. package/lib/api/chatd.js +1 -1
  64. package/lib/api/confd.js +7 -3
  65. package/lib/api/ctid-ng.js +1 -1
  66. package/lib/api/dird.js +1 -1
  67. package/lib/api/webhookd.js +1 -1
  68. package/lib/api-client.js +9 -5
  69. package/lib/checker/Checker.js +117 -23
  70. package/lib/checker/checks/aor.js +9 -5
  71. package/lib/checker/checks/api.js +9 -5
  72. package/lib/checker/checks/index.js +117 -23
  73. package/lib/checker/checks/wazo-websocket.js +1 -1
  74. package/lib/checker/checks/webrtc-transport.js +117 -23
  75. package/lib/checker/checks/webrtc.js +117 -23
  76. package/lib/domain/AdHocAPIConference.js +9 -5
  77. package/lib/domain/CallLog.js +2 -2
  78. package/lib/domain/Features.js +9 -5
  79. package/lib/domain/Meeting.js +6 -2
  80. package/lib/domain/Phone/CTIPhone.js +9 -5
  81. package/lib/domain/Phone/WebRTCPhone.js +9 -1
  82. package/lib/domain/Recording.js +1 -1
  83. package/lib/domain/__tests__/CallLog.test.js +2 -2
  84. package/lib/index.js +125 -23
  85. package/lib/lib/WazoSessionDescriptionHandler.js +1 -1
  86. package/lib/service/CallApi.js +9 -5
  87. package/lib/service/IssueReporter.js +1 -1
  88. package/lib/service/__tests__/IssueReporter.test.js +1 -1
  89. package/lib/service/getApiClient.js +9 -5
  90. package/lib/simple/Auth.js +125 -23
  91. package/lib/simple/Configuration.js +125 -23
  92. package/lib/simple/Directory.js +9 -5
  93. package/lib/simple/Phone.js +125 -23
  94. package/lib/simple/Websocket.js +1 -1
  95. package/lib/simple/index.js +125 -23
  96. package/lib/simple/room/LocalParticipant.js +125 -23
  97. package/lib/simple/room/Participant.js +125 -23
  98. package/lib/simple/room/RemoteParticipant.js +125 -23
  99. package/lib/simple/room/Room.js +125 -23
  100. package/lib/simple/room/SipRoom.js +125 -23
  101. package/lib/simple/room/Stream.js +125 -23
  102. package/lib/simple/room/__tests__/RemoteParticipant.test.js +125 -23
  103. package/lib/simple/utils.js +125 -23
  104. package/lib/utils/__tests__/api-requester.test.js +1 -1
  105. package/lib/utils/api-requester.js +1 -1
  106. package/lib/web-rtc-client.js +117 -23
  107. package/lib/websocket-client.js +1 -1
  108. package/package.json +1 -1
  109. package/src/domain/CallLog.js +1 -1
  110. package/src/domain/Meeting.js +6 -2
  111. package/src/domain/Phone/WebRTCPhone.js +7 -0
  112. package/src/domain/Recording.js +1 -1
  113. package/src/service/IssueReporter.js +1 -1
  114. package/src/web-rtc-client.js +108 -18
@@ -52,6 +52,7 @@ export const ON_MESSAGE_TRACK_UPDATED = 'onTrackUpdated';
52
52
  export const ON_NETWORK_STATS = 'onNetworkStats';
53
53
  export const ON_CHAT = 'phone/ON_CHAT';
54
54
  export const ON_SIGNAL = 'phone/ON_SIGNAL';
55
+ export const ON_DISCONNECTED = 'onDisconnected';
55
56
 
56
57
  export const MESSAGE_TYPE_CHAT = 'message/TYPE_CHAT';
57
58
  export const MESSAGE_TYPE_SIGNAL = 'message/TYPE_SIGNAL';
@@ -91,6 +92,7 @@ export const events = [
91
92
  ON_CHAT,
92
93
  ON_SIGNAL,
93
94
  ON_NETWORK_STATS,
95
+ ON_DISCONNECTED,
94
96
  ];
95
97
 
96
98
  const logger = IssueReporter.loggerFor('webrtc-phone');
@@ -1445,6 +1447,11 @@ export default class WebRTCPhone extends Emitter implements Phone {
1445
1447
  this.eventEmitter.emit(ON_UNREGISTERED);
1446
1448
  });
1447
1449
 
1450
+ this.client.on(this.client.ON_DISCONNECTED, () => {
1451
+ logger.info('WebRTC disconnected');
1452
+ this.eventEmitter.emit(ON_DISCONNECTED);
1453
+ });
1454
+
1448
1455
  this.client.on(this.client.REGISTERED, () => {
1449
1456
  logger.info('WebRTC registered', {
1450
1457
  shouldSendReinvite: this.shouldSendReinvite,
@@ -24,7 +24,7 @@ export default class Recording {
24
24
  start: Date;
25
25
  uuid: string;
26
26
 
27
- static parseMany(recordings: RecordingResponse[]): Recording[] {
27
+ static parseMany(recordings: RecordingResponse[] = []): Recording[] {
28
28
  return recordings.map(item => Recording.parse(item));
29
29
  }
30
30
 
@@ -316,7 +316,7 @@ class IssueReporter {
316
316
  payload._retry = retry + 1;
317
317
  }
318
318
 
319
- this._sendDebugToGrafana(body, retry + 1);
319
+ this._sendDebugToGrafana(payload, retry + 1);
320
320
  }, 5000 + retry * 1000);
321
321
  });
322
322
  }
@@ -69,6 +69,7 @@ const ON_REINVITE = 'reinvite';
69
69
  const ON_ERROR = 'onError';
70
70
  const ON_SCREEN_SHARING_REINVITE = 'onScreenSharingReinvite';
71
71
  const ON_NETWORK_STATS = 'onNetworkStats';
72
+ const ON_DISCONNECTED = 'onDisconnected';
72
73
 
73
74
  export const events = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
74
75
  export const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
@@ -145,6 +146,7 @@ export default class WebRTCClient extends Emitter {
145
146
  ON_ERROR: string;
146
147
  ON_SCREEN_SHARING_REINVITE: string;
147
148
  ON_NETWORK_STATS: string;
149
+ ON_DISCONNECTED: string;
148
150
 
149
151
  static isAPrivateIp(ip: string): boolean {
150
152
  const regex = /^(?:10|127|172\.(?:1[6-9]|2[0-9]|3[01])|192\.168)\..*/;
@@ -210,6 +212,7 @@ export default class WebRTCClient extends Emitter {
210
212
  this.ON_ERROR = ON_ERROR;
211
213
  this.ON_SCREEN_SHARING_REINVITE = ON_SCREEN_SHARING_REINVITE;
212
214
  this.ON_NETWORK_STATS = ON_NETWORK_STATS;
215
+ this.ON_DISCONNECTED = ON_DISCONNECTED;
213
216
  }
214
217
 
215
218
  configureMedia(media: MediaConfig) {
@@ -811,7 +814,7 @@ export default class WebRTCClient extends Emitter {
811
814
  // We search for the last transceiver without `video-` in the mid (video- means remote transceiver)
812
815
  const transceivers = pc.getTransceivers();
813
816
  const transceiverIdx = lastIndexOf(transceivers, transceiver =>
814
- transceiver.sender.track === null && transceiver.mid.indexOf('video') === -1);
817
+ transceiver.sender.track === null && transceiver.mid && transceiver.mid.indexOf('video') === -1);
815
818
 
816
819
  videoSender = transceiverIdx !== -1 ? transceivers[transceiverIdx].sender : null;
817
820
  } else {
@@ -1057,10 +1060,13 @@ export default class WebRTCClient extends Emitter {
1057
1060
  return null;
1058
1061
  }
1059
1062
 
1060
- // let's update the local value
1061
- if (this.audio && this.audio.deviceId) {
1062
- // $FlowFixMe
1063
- this.audio.deviceId.exact = id;
1063
+ // let's update the local audio value
1064
+ if (this.audio) {
1065
+ this.audio = {
1066
+ deviceId: {
1067
+ exact: id,
1068
+ },
1069
+ };
1064
1070
  }
1065
1071
 
1066
1072
  if (session) {
@@ -1073,6 +1079,9 @@ export default class WebRTCClient extends Emitter {
1073
1079
  const sender = pc && pc.getSenders().find(s => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
1074
1080
 
1075
1081
  if (sender) {
1082
+ if (sender.track) {
1083
+ audioTrack.enabled = sender.track.enabled;
1084
+ }
1076
1085
  sender.replaceTrack(audioTrack);
1077
1086
  }
1078
1087
 
@@ -1097,7 +1106,7 @@ export default class WebRTCClient extends Emitter {
1097
1106
  return null;
1098
1107
  }
1099
1108
 
1100
- // let's update the local value
1109
+ // let's update the local video value
1101
1110
  if (this.video) {
1102
1111
  this.video = {
1103
1112
  deviceId: {
@@ -1132,12 +1141,21 @@ export default class WebRTCClient extends Emitter {
1132
1141
  return navigator.mediaDevices.getUserMedia(constraints).then(async stream => {
1133
1142
  const videoTrack = stream.getVideoTracks()[0];
1134
1143
  let sender = pc && pc.getSenders().find(s => videoTrack && s && s.track && s.track.kind === videoTrack.kind);
1144
+ let wasTrackEnabled = false;
1135
1145
  if (!sender) {
1136
1146
  sender = pc && pc.getSenders().find(s => !s.track);
1137
1147
  }
1138
1148
 
1139
1149
  if (sender) {
1140
- sender.replaceTrack(videoTrack);
1150
+ // No video track means video not enabled
1151
+ wasTrackEnabled = sender.track ? sender.track.enabled : false;
1152
+ videoTrack.enabled = wasTrackEnabled;
1153
+
1154
+ if (!wasTrackEnabled) {
1155
+ videoTrack.stop();
1156
+ }
1157
+
1158
+ sender.replaceTrack(wasTrackEnabled ? videoTrack : null);
1141
1159
  }
1142
1160
 
1143
1161
  // let's update the local stream
@@ -1821,6 +1839,7 @@ export default class WebRTCClient extends Emitter {
1821
1839
 
1822
1840
  this.updateRemoteStream(this.getSipSessionId(session));
1823
1841
 
1842
+ const pc = session.sessionDescriptionHandler.peerConnection;
1824
1843
  const onTrack = (event: any) => {
1825
1844
  const isAudioOnly = this._isAudioOnly(session);
1826
1845
  const { kind, label, readyState, id, muted } = event.track;
@@ -1840,6 +1859,12 @@ export default class WebRTCClient extends Emitter {
1840
1859
 
1841
1860
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
1842
1861
 
1862
+ pc.oniceconnectionstatechange = () => {
1863
+ if (pc.iceConnectionState === 'disconnected') {
1864
+ this.eventEmitter.emit(ON_DISCONNECTED);
1865
+ }
1866
+ };
1867
+
1843
1868
  if (withEvent) {
1844
1869
  this.eventEmitter.emit(ACCEPTED, session, sessionDialog);
1845
1870
  }
@@ -2035,24 +2060,89 @@ export default class WebRTCClient extends Emitter {
2035
2060
  const session = this.getSipSession(sessionId);
2036
2061
 
2037
2062
  const stats = session ? await this.getStats(session) : null;
2038
- if (!stats) {
2063
+ if (!stats || !(sessionId in this.sessionNetworkStats)) {
2039
2064
  return;
2040
2065
  }
2041
2066
 
2067
+ const networkStats: Object = {
2068
+ audioBytesSent: 0,
2069
+ videoBytesSent: 0,
2070
+ videoBytesReceived: 0,
2071
+ audioBytesReceived: 0,
2072
+ };
2073
+ const nbStats = this.sessionNetworkStats[sessionId].length;
2074
+ const lastNetworkStats = this.sessionNetworkStats[sessionId][nbStats - 1];
2075
+ const lastAudioSent = lastNetworkStats ? lastNetworkStats.audioBytesSent : 0;
2076
+ const lastVideoSent = lastNetworkStats ? lastNetworkStats.videoBytesSent : 0;
2077
+ const lastAudioReceived = lastNetworkStats ? lastNetworkStats.audioBytesReceived : 0;
2078
+ const lastVideoReceived = lastNetworkStats ? lastNetworkStats.videoBytesReceived : 0;
2079
+ const lastTransportSent = lastNetworkStats ? lastNetworkStats.transportSent : 0;
2080
+ const lastTransportReceived = lastNetworkStats ? lastNetworkStats.transportReceived : 0;
2081
+ let audioBytesSent = 0;
2082
+ let audioBytesReceived = 0;
2083
+ let videoBytesSent = 0;
2084
+ let videoBytesReceived = 0;
2085
+ let transportSent = 0;
2086
+ let transportReceived = 0;
2087
+ let packetsLost = 0;
2088
+
2042
2089
  stats.forEach(report => {
2043
- if (report.type === 'inbound-rtp') {
2044
- if (report.kind === 'audio') {
2045
- const networkStats = {
2046
- packetsLost: report.packetsLost,
2047
- packetsReceived: report.packetsReceived,
2048
- jitter: report.jitter,
2049
- };
2050
-
2051
- this.eventEmitter.emit(ON_NETWORK_STATS, session, networkStats, this.sessionNetworkStats[sessionId]);
2052
- this.sessionNetworkStats[sessionId].push(networkStats);
2090
+ if (report.type === 'outbound-rtp' && report.kind === 'audio') {
2091
+ audioBytesSent += report.bytesSent + report.headerBytesSent;
2092
+ }
2093
+ if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
2094
+ audioBytesSent += report.bytesSent;
2095
+ }
2096
+ if (report.type === 'outbound-rtp' && report.kind === 'video') {
2097
+ videoBytesSent += report.bytesSent + report.headerBytesSent;
2098
+ }
2099
+ if (report.type === 'inbound-rtp' && report.kind === 'audio') {
2100
+ packetsLost += report.packetsLost;
2101
+ networkStats.packetsReceived = report.packetsReceived;
2102
+ audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
2103
+ }
2104
+ if (report.type === 'inbound-rtp' && report.kind === 'video') {
2105
+ videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
2106
+ }
2107
+ if (report.type === 'outbound-rtp' && report.kind === 'video') {
2108
+ if ('framesPerSecond' in report) {
2109
+ networkStats.framesPerSecond = report.framesPerSecond;
2110
+ }
2111
+ if ('framerateMean' in report) {
2112
+ // framerateMean is only available in FF
2113
+ networkStats.framesPerSecond = Math.round(report.framerateMean);
2053
2114
  }
2054
2115
  }
2116
+ if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
2117
+ packetsLost += report.packetsLost;
2118
+ networkStats.roundTripTime = report.roundTripTime;
2119
+ networkStats.jitter = report.jitter;
2120
+ }
2121
+ if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
2122
+ packetsLost += report.packetsLost;
2123
+ }
2124
+ if (report.type === 'transport') {
2125
+ transportSent += report.bytesSent;
2126
+ transportReceived += report.bytesReceived;
2127
+ }
2055
2128
  });
2129
+
2130
+ networkStats.packetsLost = packetsLost;
2131
+ networkStats.audioBytesSent = audioBytesSent;
2132
+ networkStats.audioBytesReceived = audioBytesReceived;
2133
+ networkStats.videoBytesSent = videoBytesSent;
2134
+ networkStats.videoBytesReceived = videoBytesReceived;
2135
+ networkStats.transportSent = transportSent;
2136
+ networkStats.transportReceived = transportReceived;
2137
+
2138
+ const bandwidth = (networkStats.audioBytesSent - lastAudioSent) + (networkStats.videoBytesSent - lastVideoSent)
2139
+ + (networkStats.audioBytesReceived - lastAudioReceived) + (networkStats.videoBytesReceived - lastVideoReceived)
2140
+ + (networkStats.transportReceived - lastTransportReceived) + (networkStats.transportSent - lastTransportSent);
2141
+
2142
+ networkStats.bandwidth = bandwidth;
2143
+
2144
+ this.eventEmitter.emit(ON_NETWORK_STATS, session, networkStats, this.sessionNetworkStats[sessionId]);
2145
+ this.sessionNetworkStats[sessionId].push(networkStats);
2056
2146
  }
2057
2147
 
2058
2148
  }