@wazo/sdk 0.38.7 → 0.38.10

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 (121) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/api-client.test.js +163 -2
  3. package/esm/__tests__/web-rtc-client.test.js +248 -27
  4. package/esm/api/auth.js +12 -0
  5. package/esm/api/calld.js +8 -0
  6. package/esm/api/confd.js +134 -2
  7. package/esm/api/ctid-ng.js +1 -0
  8. package/esm/api-client.js +163 -2
  9. package/esm/checker/Checker.js +204 -24
  10. package/esm/checker/checks/aor.js +163 -2
  11. package/esm/checker/checks/api.js +163 -2
  12. package/esm/checker/checks/index.js +204 -24
  13. package/esm/checker/checks/wazo-websocket.js +2 -0
  14. package/esm/checker/checks/webrtc-transport.js +202 -24
  15. package/esm/checker/checks/webrtc.js +202 -24
  16. package/esm/domain/AdHocAPIConference.js +170 -4
  17. package/esm/domain/Features.js +170 -4
  18. package/esm/domain/Meeting.js +18 -0
  19. package/esm/domain/MeetingAuthorization.js +70 -0
  20. package/esm/domain/Phone/CTIPhone.js +170 -4
  21. package/esm/domain/Phone/WebRTCPhone.js +2 -3
  22. package/esm/domain/__tests__/Meeting.test.js +87 -1
  23. package/esm/domain/__tests__/MeetingAuthorization.test.js +109 -0
  24. package/esm/index.js +300 -36
  25. package/esm/service/CallApi.js +170 -4
  26. package/esm/service/getApiClient.js +176 -5
  27. package/esm/simple/Auth.js +301 -37
  28. package/esm/simple/Configuration.js +300 -36
  29. package/esm/simple/Directory.js +170 -4
  30. package/esm/simple/Phone.js +300 -36
  31. package/esm/simple/Softphone.js +5 -0
  32. package/esm/simple/Websocket.js +3 -0
  33. package/esm/simple/index.js +300 -36
  34. package/esm/simple/room/LocalParticipant.js +300 -36
  35. package/esm/simple/room/Participant.js +300 -36
  36. package/esm/simple/room/RemoteParticipant.js +300 -36
  37. package/esm/simple/room/Room.js +300 -36
  38. package/esm/simple/room/SipRoom.js +300 -36
  39. package/esm/simple/room/Stream.js +300 -36
  40. package/esm/simple/room/__tests__/Participant.test.js +14812 -0
  41. package/esm/simple/room/__tests__/RemoteParticipant.test.js +300 -36
  42. package/esm/simple/utils.js +300 -36
  43. package/esm/utils/__tests__/object.test.js +57 -0
  44. package/esm/utils/__tests__/string.test.js +30 -0
  45. package/esm/utils/object.js +24 -0
  46. package/esm/utils/string.js +10 -0
  47. package/esm/web-rtc-client.js +202 -24
  48. package/esm/websocket-client.js +3 -1
  49. package/lib/__tests__/api-client.test.js +163 -2
  50. package/lib/__tests__/web-rtc-client.test.js +248 -27
  51. package/lib/api/auth.js +12 -0
  52. package/lib/api/calld.js +8 -0
  53. package/lib/api/confd.js +134 -2
  54. package/lib/api/ctid-ng.js +1 -0
  55. package/lib/api-client.js +163 -2
  56. package/lib/checker/Checker.js +204 -24
  57. package/lib/checker/checks/aor.js +163 -2
  58. package/lib/checker/checks/api.js +163 -2
  59. package/lib/checker/checks/index.js +204 -24
  60. package/lib/checker/checks/wazo-websocket.js +2 -0
  61. package/lib/checker/checks/webrtc-transport.js +202 -24
  62. package/lib/checker/checks/webrtc.js +202 -24
  63. package/lib/domain/AdHocAPIConference.js +170 -4
  64. package/lib/domain/Features.js +170 -4
  65. package/lib/domain/Meeting.js +18 -0
  66. package/lib/domain/MeetingAuthorization.js +79 -0
  67. package/lib/domain/Phone/CTIPhone.js +170 -4
  68. package/lib/domain/Phone/WebRTCPhone.js +2 -3
  69. package/lib/domain/__tests__/Meeting.test.js +87 -1
  70. package/lib/domain/__tests__/MeetingAuthorization.test.js +111 -0
  71. package/lib/index.js +300 -36
  72. package/lib/service/CallApi.js +170 -4
  73. package/lib/service/getApiClient.js +176 -4
  74. package/lib/simple/Auth.js +301 -36
  75. package/lib/simple/Configuration.js +300 -36
  76. package/lib/simple/Directory.js +170 -4
  77. package/lib/simple/Phone.js +300 -36
  78. package/lib/simple/Softphone.js +5 -0
  79. package/lib/simple/Websocket.js +3 -0
  80. package/lib/simple/index.js +300 -36
  81. package/lib/simple/room/LocalParticipant.js +300 -36
  82. package/lib/simple/room/Participant.js +300 -36
  83. package/lib/simple/room/RemoteParticipant.js +300 -36
  84. package/lib/simple/room/Room.js +300 -36
  85. package/lib/simple/room/SipRoom.js +300 -36
  86. package/lib/simple/room/Stream.js +300 -36
  87. package/lib/simple/room/__tests__/Participant.test.js +14822 -0
  88. package/lib/simple/room/__tests__/RemoteParticipant.test.js +300 -36
  89. package/lib/simple/utils.js +300 -36
  90. package/lib/utils/__tests__/object.test.js +59 -0
  91. package/lib/utils/__tests__/string.test.js +32 -0
  92. package/lib/utils/object.js +28 -0
  93. package/lib/utils/string.js +14 -0
  94. package/lib/web-rtc-client.js +202 -24
  95. package/lib/websocket-client.js +3 -0
  96. package/package.json +1 -1
  97. package/src/__tests__/web-rtc-client.test.js +46 -3
  98. package/src/api/auth.js +12 -0
  99. package/src/api/calld.js +8 -0
  100. package/src/api/confd.js +43 -2
  101. package/src/api-client.js +8 -0
  102. package/src/domain/Meeting.js +20 -0
  103. package/src/domain/MeetingAuthorization.js +67 -0
  104. package/src/domain/Phone/WebRTCPhone.js +1 -3
  105. package/src/domain/__tests__/Meeting.test.js +70 -1
  106. package/src/domain/__tests__/MeetingAuthorization.test.js +58 -0
  107. package/src/service/getApiClient.js +13 -2
  108. package/src/simple/Auth.js +35 -4
  109. package/src/simple/Softphone.js +5 -0
  110. package/src/simple/index.js +2 -1
  111. package/src/simple/room/Participant.js +40 -0
  112. package/src/simple/room/Room.js +2 -2
  113. package/src/simple/room/SipRoom.js +1 -1
  114. package/src/simple/room/__tests__/Participant.test.js +81 -0
  115. package/src/types/WebSocketMessage.js +7 -1
  116. package/src/utils/__tests__/object.test.js +35 -0
  117. package/src/utils/__tests__/string.test.js +23 -0
  118. package/src/utils/object.js +15 -0
  119. package/src/utils/string.js +8 -0
  120. package/src/web-rtc-client.js +39 -22
  121. package/src/websocket-client.js +2 -0
@@ -143,7 +143,7 @@ class Room extends Emitter {
143
143
  logger.info('connecting to room', { extension, audioOnly, room: !!room });
144
144
 
145
145
  if (!room) {
146
- await Wazo.Phone.connect();
146
+ await Wazo.Phone.connect({ media: constraints });
147
147
 
148
148
  const withCamera = constraints && !!constraints.video;
149
149
 
@@ -590,7 +590,7 @@ class Room extends Emitter {
590
590
  const participant: ?Participant = this._getParticipantFromCallId(status.callId);
591
591
 
592
592
  if (participant) {
593
- // we're received, so no need to broadcast, hence the input false arg
593
+ // we're receiving, so no need to broadcast
594
594
  participant.updateStatus(status, false);
595
595
  }
596
596
  break;
@@ -13,7 +13,7 @@ class SipRoom extends Room {
13
13
  logger.info('connecting to sip room', { extension, audioOnly, room: !!room });
14
14
 
15
15
  if (!room) {
16
- await Wazo.Phone.connect();
16
+ await Wazo.Phone.connect({ media: constraints });
17
17
 
18
18
  const withCamera = constraints && !!constraints.video;
19
19
 
@@ -0,0 +1,81 @@
1
+ // Using directly Wazo to avoid issues with require cycle
2
+ import getApiClient from '../../../service/getApiClient';
3
+ import Wazo from '../../index';
4
+ import Room from '../Room';
5
+
6
+ jest.mock('../../../service/getApiClient');
7
+
8
+ describe('Participant', () => {
9
+ describe('ban', () => {
10
+ it('should throw an error when there is no meeting', async () => {
11
+ const room = new Room();
12
+ const participant = new Wazo.RemoteParticipant(room, {
13
+ call_id: 'id',
14
+ caller_id_name: 'Alice',
15
+ caller_id_number: 'number',
16
+ });
17
+
18
+ await expect(async () => participant.ban())
19
+ .rejects.toThrow('Attempting to ban a participant without a `meetingUuid`');
20
+ });
21
+
22
+ it('should call the api', async () => {
23
+ const number = '1234';
24
+ const meetingUuid = 'some-meeting-uuid';
25
+ const callId = 'some-call-id';
26
+ const room = new Room();
27
+ room.setMeetingUuid(meetingUuid);
28
+
29
+ const banMeetingParticipant = jest.fn();
30
+
31
+ getApiClient.mockImplementation(() => ({
32
+ calld: {
33
+ banMeetingParticipant,
34
+ },
35
+ }));
36
+
37
+ const participant = new Wazo.RemoteParticipant(room, {
38
+ call_id: callId,
39
+ caller_id_name: 'Alice',
40
+ caller_id_number: number,
41
+ });
42
+
43
+ participant.onBan = jest.fn();
44
+
45
+ await participant.ban();
46
+ expect(banMeetingParticipant).toHaveBeenCalledWith(meetingUuid, callId);
47
+ expect(participant.onBan).toHaveBeenCalledWith(true);
48
+ });
49
+
50
+ it('should call the api with a delay', async () => {
51
+ const number = '1234';
52
+ const meetingUuid = 'some-meeting-uuid';
53
+ const callId = 'some-call-id';
54
+ const someDelay = 2;
55
+ const room = new Room();
56
+ room.setMeetingUuid(meetingUuid);
57
+
58
+ const banMeetingParticipant = jest.fn();
59
+
60
+ getApiClient.mockImplementation(() => ({
61
+ calld: {
62
+ banMeetingParticipant,
63
+ },
64
+ }));
65
+
66
+ const participant = new Wazo.RemoteParticipant(room, {
67
+ call_id: callId,
68
+ caller_id_name: 'Alice',
69
+ caller_id_number: number,
70
+ });
71
+
72
+ participant.delay = jest.fn();
73
+ participant.onBan = jest.fn();
74
+
75
+ await participant.ban(someDelay);
76
+ expect(banMeetingParticipant).toHaveBeenCalledWith(meetingUuid, callId);
77
+ expect(participant.delay).toHaveBeenCalledWith(someDelay);
78
+ expect(participant.onBan).toHaveBeenCalledWith(true);
79
+ });
80
+ });
81
+ });
@@ -8,6 +8,7 @@ import type {
8
8
  import type { ChatMessageResponse } from '../domain/ChatMessage';
9
9
  import ChatRoom from '../domain/ChatRoom';
10
10
  import Meeting from '../domain/Meeting';
11
+ import type MeetingAuthorization from '../domain/MeetingAuthorization';
11
12
 
12
13
  type WebSocketBaseMessage = {
13
14
  op: string,
@@ -189,6 +190,10 @@ type AgentPaused = WebSocketBaseMessage & { data: any, name: 'agent_paused' };
189
190
  type AgentUnpaused = WebSocketBaseMessage & { data: any, name: 'agent_unpaused' };
190
191
 
191
192
  type MeetingUserProgress = WebSocketBaseMessage & { data: Meeting, name: 'meeting_user_progress' };
193
+ type MeetingAuthorizationPending = WebSocketBaseMessage & {
194
+ data: MeetingAuthorization,
195
+ name: 'meeting_authorization_pending'
196
+ };
192
197
 
193
198
  export type WebSocketMessage =
194
199
  | CallCreated
@@ -223,4 +228,5 @@ export type WebSocketMessage =
223
228
  | AgentStatusUpdate
224
229
  | AgentPaused
225
230
  | AgentUnpaused
226
- | MeetingUserProgress;
231
+ | MeetingUserProgress
232
+ | MeetingAuthorizationPending;
@@ -0,0 +1,35 @@
1
+ // @flow
2
+ import { convertKeysFromCamelToUnderscore } from '../object';
3
+
4
+ describe('object utils', () => {
5
+ describe('convertKeysFromCamelToUnderscore', () => {
6
+ it('should throw an error when input is not an object', () => {
7
+ const msg = 'Input is not an object';
8
+ expect(() => convertKeysFromCamelToUnderscore(true)).toThrow(msg);
9
+ expect(() => convertKeysFromCamelToUnderscore(null)).toThrow(msg);
10
+ expect(() => convertKeysFromCamelToUnderscore(undefined)).toThrow(msg);
11
+ expect(() => convertKeysFromCamelToUnderscore([])).toThrow(msg);
12
+ expect(() => convertKeysFromCamelToUnderscore('some-string')).toThrow(msg);
13
+ });
14
+
15
+ it('should convert camel-cased keys to underscore', () => {
16
+ let value = Math.random();
17
+ expect(convertKeysFromCamelToUnderscore({ LoremIpsum: value })).toEqual({ lorem_ipsum: value });
18
+ value = Math.random();
19
+ expect(convertKeysFromCamelToUnderscore({ loremIpsum: value })).toEqual({ lorem_ipsum: value });
20
+ value = Math.random();
21
+ expect(convertKeysFromCamelToUnderscore({ 'lorem-ipsum': value })).toEqual({ 'lorem-ipsum': value });
22
+ value = Math.random();
23
+ expect(convertKeysFromCamelToUnderscore({ L123: value })).toEqual({ l123: value });
24
+ });
25
+
26
+ it('should handle multi-leveled object', () => {
27
+ const value = Math.random();
28
+ expect(convertKeysFromCamelToUnderscore({ LoremIpsum: { DoloreSit: { Amet: value }, regular: 'reg' } }))
29
+ .toEqual({ lorem_ipsum: { dolore_sit: { amet: value }, regular: 'reg' } });
30
+
31
+ expect(convertKeysFromCamelToUnderscore({ LoremIpsum: { DoloreSit: { Amet: [value] }, regular: ['something'] } }))
32
+ .toEqual({ lorem_ipsum: { dolore_sit: { amet: [value] }, regular: ['something'] } });
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,23 @@
1
+ import { camelToUnderscore } from '../string';
2
+
3
+ describe('string utils', () => {
4
+ describe('camelToUnderscore', () => {
5
+ it('', () => {
6
+ expect(() => camelToUnderscore(null)).toThrow('Input is not a string');
7
+ expect(() => camelToUnderscore(undefined)).toThrow('Input is not a string');
8
+ expect(() => camelToUnderscore({})).toThrow('Input is not a string');
9
+ expect(() => camelToUnderscore([])).toThrow('Input is not a string');
10
+ });
11
+
12
+ it('should convert camel-cased string to underscore', () => {
13
+ expect(camelToUnderscore('loremIpsum')).toEqual('lorem_ipsum');
14
+ expect(camelToUnderscore('lorem-ipsum')).toEqual('lorem-ipsum');
15
+ expect(camelToUnderscore('')).toEqual('');
16
+ });
17
+
18
+ it('should not prefix string with an underscore', () => {
19
+ expect(camelToUnderscore('LoremIpsum')).toEqual('lorem_ipsum');
20
+ expect(camelToUnderscore('L123')).toEqual('l123');
21
+ });
22
+ });
23
+ });
@@ -0,0 +1,15 @@
1
+ // @flow
2
+
3
+ import { camelToUnderscore } from './string';
4
+
5
+ export const convertKeysFromCamelToUnderscore = (args: Object) => {
6
+ if (!args || typeof args !== 'object' || Array.isArray(args)) {
7
+ throw new Error('Input is not an object');
8
+ }
9
+
10
+ return Object.keys(args).reduce((acc, key) => {
11
+ acc[camelToUnderscore(key)] = typeof args[key] === 'object' && !Array.isArray(args[key])
12
+ ? convertKeysFromCamelToUnderscore(args[key]) : args[key];
13
+ return acc;
14
+ }, {});
15
+ };
@@ -0,0 +1,8 @@
1
+ // @flow
2
+
3
+ export const camelToUnderscore = (key: string) => {
4
+ if (typeof key !== 'string') {
5
+ throw new Error('Input is not a string');
6
+ }
7
+ return key.charAt(0).toLowerCase() + key.substring(1).replace(/([A-Z])/g, '_$1').toLowerCase();
8
+ };
@@ -1070,7 +1070,7 @@ export default class WebRTCClient extends Emitter {
1070
1070
  });
1071
1071
  }
1072
1072
 
1073
- changeAudioInputDevice(id: string, session: ?Inviter, force: ?boolean) {
1073
+ async changeAudioInputDevice(id: string, session: ?Inviter, force: ?boolean) {
1074
1074
  const currentId = this.getAudioDeviceId();
1075
1075
  logger.info('setting audio input device', { id, currentId, session: !!session });
1076
1076
 
@@ -1078,33 +1078,50 @@ export default class WebRTCClient extends Emitter {
1078
1078
  return null;
1079
1079
  }
1080
1080
 
1081
+ // in order to handle an audio track change for default devices
1082
+ // we need the actual id of the device (not 'default')
1083
+ let deviceId = id;
1084
+ if (id === 'default' && navigator.mediaDevices) {
1085
+ const devices = await navigator.mediaDevices.enumerateDevices();
1086
+ const defaultDevice = devices.find(device => device.deviceId === 'default');
1087
+ if (defaultDevice) {
1088
+ const deviceLabel = defaultDevice.label.replace('Default - ', '');
1089
+ const targetDevice = devices.find(device => device.label === deviceLabel);
1090
+ if (targetDevice) {
1091
+ deviceId = targetDevice.deviceId;
1092
+ if (!force && deviceId === currentId) {
1093
+ return null;
1094
+ }
1095
+ }
1096
+ }
1097
+ }
1098
+
1081
1099
  // let's update the local audio value
1082
1100
  if (this.audio) {
1083
1101
  this.audio = {
1084
1102
  deviceId: {
1085
- exact: id,
1103
+ exact: deviceId,
1086
1104
  },
1087
1105
  };
1088
1106
  }
1089
1107
 
1090
- if (session) {
1108
+ if (session && navigator.mediaDevices) {
1091
1109
  const sdh = session.sessionDescriptionHandler;
1092
1110
  const pc = sdh.peerConnection;
1093
1111
 
1094
- // $FlowFixMe
1095
- return navigator.mediaDevices.getUserMedia({ audio: { deviceId: { exact: id } } }).then(async stream => {
1096
- const audioTrack = stream.getAudioTracks()[0];
1097
- const sender = pc && pc.getSenders().find(s => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
1112
+ const constraints = { audio: { deviceId: { exact: deviceId } } };
1113
+ const stream = await navigator.mediaDevices.getUserMedia(constraints);
1114
+ const audioTrack = stream.getAudioTracks()[0];
1115
+ const sender = pc && pc.getSenders().find(s => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
1098
1116
 
1099
- if (sender) {
1100
- if (sender.track) {
1101
- audioTrack.enabled = sender.track.enabled;
1102
- }
1103
- sender.replaceTrack(audioTrack);
1117
+ if (sender) {
1118
+ if (sender.track) {
1119
+ audioTrack.enabled = sender.track.enabled;
1104
1120
  }
1121
+ sender.replaceTrack(audioTrack);
1122
+ }
1105
1123
 
1106
- return stream;
1107
- });
1124
+ return stream;
1108
1125
  }
1109
1126
  }
1110
1127
 
@@ -1124,14 +1141,14 @@ export default class WebRTCClient extends Emitter {
1124
1141
  return null;
1125
1142
  }
1126
1143
 
1127
- // let's update the local video value
1128
- if (this.video) {
1129
- this.video = {
1130
- deviceId: {
1131
- exact: id,
1132
- },
1133
- };
1134
- }
1144
+ // let's make sure we don't lose other video constraints settings -- width, height, frameRate...
1145
+ const videoObject = typeof this.video === 'object' ? this.video : {};
1146
+ this.video = {
1147
+ ...videoObject,
1148
+ deviceId: {
1149
+ exact: id,
1150
+ },
1151
+ };
1135
1152
  }
1136
1153
 
1137
1154
  changeSessionVideoInputDevice(id: ?string, session: Inviter) {
@@ -94,6 +94,7 @@ export const AGENT_UNPAUSED = 'agent_unpaused';
94
94
  export const CONFERENCE_ADHOC_PARTICIPANT_LEFT = 'conference_adhoc_participant_left';
95
95
  export const CONFERENCE_ADHOC_DELETED = 'conference_adhoc_deleted';
96
96
  export const MEETING_USER_PROGRESS = 'meeting_user_progress';
97
+ export const MEETING_USER_GUEST_AUTHORIZATION_CREATED = 'meeting_user_guest_authorization_created';
97
98
 
98
99
  const BLACKLIST_EVENTS = [
99
100
  CHAT_MESSAGE_SENT,
@@ -448,6 +449,7 @@ WebSocketClient.eventLists = [
448
449
  CONFERENCE_ADHOC_PARTICIPANT_LEFT,
449
450
  CONFERENCE_ADHOC_DELETED,
450
451
  MEETING_USER_PROGRESS,
452
+ MEETING_USER_GUEST_AUTHORIZATION_CREATED,
451
453
  ];
452
454
 
453
455
  export default WebSocketClient;