@telegenta/webclient 2.0.12 → 3.0.1

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 (105) hide show
  1. package/README.md +102 -81
  2. package/demos/add_phone_number.html +8 -7
  3. package/demos/calldata_available.html +5 -5
  4. package/demos/embedded_config.html +3 -3
  5. package/demos/event_client.html +226 -211
  6. package/demos/phone_client.html +540 -514
  7. package/demos/styles.css +0 -0
  8. package/dist/telegenta.js +3663 -0
  9. package/dist/telegenta.min.js +1 -0
  10. package/docs/EventClient.html +3 -1093
  11. package/docs/EventServiceNotConnected.html +3 -0
  12. package/docs/InvalidMediaDevice.html +3 -0
  13. package/docs/InvalidOptions.html +3 -0
  14. package/docs/InvalidParameter.html +3 -0
  15. package/docs/LogHandler.html +7 -0
  16. package/docs/MediaNotPrepared.html +3 -0
  17. package/docs/NoActiveSession.html +3 -0
  18. package/docs/NotAllowed.html +3 -0
  19. package/docs/NotReady.html +3 -0
  20. package/docs/Phone.html +4 -2837
  21. package/docs/Request.html +3 -0
  22. package/docs/Requestor.html +3 -0
  23. package/docs/Session.html +3 -2599
  24. package/docs/UnableToConnect.html +3 -0
  25. package/docs/data/search.json +1 -0
  26. package/docs/event-client.js.html +352 -0
  27. package/docs/exceptions.js.html +104 -0
  28. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  29. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  30. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  31. package/docs/global.html +5 -4950
  32. package/docs/index.html +3 -66
  33. package/docs/logger.js.html +106 -0
  34. package/docs/phone-client.js.html +2175 -0
  35. package/docs/requestor.js.html +223 -0
  36. package/docs/scripts/core.js +726 -0
  37. package/docs/scripts/core.min.js +23 -0
  38. package/docs/scripts/resize.js +90 -0
  39. package/docs/scripts/search.js +265 -0
  40. package/docs/scripts/search.min.js +6 -0
  41. package/docs/scripts/{prettify → third-party}/Apache-License-2.0.txt +202 -202
  42. package/docs/scripts/third-party/fuse.js +9 -0
  43. package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  44. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  45. package/docs/scripts/third-party/hljs-original.js +5171 -0
  46. package/docs/scripts/third-party/hljs.js +1 -0
  47. package/docs/scripts/third-party/popper.js +5 -0
  48. package/docs/scripts/third-party/tippy.js +1 -0
  49. package/docs/scripts/third-party/tocbot.js +672 -0
  50. package/docs/scripts/third-party/tocbot.min.js +1 -0
  51. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  52. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  53. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  54. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  55. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  56. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  57. package/package.json +38 -26
  58. package/babel.config.js +0 -16
  59. package/browser/telegenta.min.js +0 -1
  60. package/demos/telegenta.min.js +0 -1
  61. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  62. package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
  63. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  64. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  65. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  66. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  67. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  68. package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
  69. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  70. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  71. package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
  72. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  73. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  74. package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  75. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  76. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  77. package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
  78. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  79. package/docs/fonts/OpenSans-Semibold-webfont.eot +0 -0
  80. package/docs/fonts/OpenSans-Semibold-webfont.svg +0 -1830
  81. package/docs/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  82. package/docs/fonts/OpenSans-Semibold-webfont.woff +0 -0
  83. package/docs/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  84. package/docs/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
  85. package/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  86. package/docs/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  87. package/docs/scripts/linenumber.js +0 -25
  88. package/docs/scripts/prettify/lang-css.js +0 -2
  89. package/docs/scripts/prettify/prettify.js +0 -28
  90. package/docs/styles/jsdoc-default.css +0 -692
  91. package/docs/styles/prettify-jsdoc.css +0 -111
  92. package/docs/styles/prettify-tomorrow.css +0 -132
  93. package/embedded_client/embedded_phone.js +0 -325
  94. package/embedded_client/index.html +0 -201
  95. package/embedded_client/server.php +0 -28
  96. package/embedded_client/styles.css +0 -310
  97. package/embedded_client/tiny_rest_client.php +0 -73
  98. package/embedded_client/webphone_sprites.png +0 -0
  99. package/es5/event-client.js +0 -277
  100. package/es5/index.js +0 -44
  101. package/es5/phone-client.js +0 -1336
  102. package/src/event-client.js +0 -1
  103. package/src/index.js +0 -10
  104. package/src/phone-client.js +0 -1
  105. package/webpack.config.js +0 -39
@@ -1,558 +1,584 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Telegenta Phone client Demo</title>
6
- <script src="telegenta.min.js"></script>
7
- <link rel="stylesheet" type="text/css" href="styles.css">
8
- </head>
9
-
10
- <body>
11
- <!-- Logo -->
12
- <div class="groupelementsnoline" id="Telegenta"></div>
13
- <!-- Logo end -->
14
- <div>
15
- <div class="groupelementsnoline">
16
- <h2>Telegenta Phone Client Demo</h2>
17
- </div>
18
- <div class="groupelements">
19
- <H3>STEP 1: Get account list</H3>
20
- <div class="inputelements">
21
- <label for="api_key">API Key</label>
22
- <input type="text" size="40" id="api_key" placeholder="Enter API Key"
23
- value="">
24
- <button onclick="populateSelectElements()">Get sip accounts</button>
3
+ <meta name="keywords" content="telegenta, phone client, webrtc, demo" />
4
+ <meta name="description" content="Telegenta Phone client demo application using telegenta client library" />
5
+
6
+ <head>
7
+ <meta charset="UTF-8" />
8
+ <title>Telegenta Phone client Demo</title>
9
+ <script src="../dist/telegenta.min.js"></script>
10
+ <link rel="stylesheet" type="text/css" href="styles.css" />
11
+ </head>
12
+
13
+ <body>
14
+ <!-- Logo -->
15
+ <div class="groupelementsnoline" id="Telegenta"></div>
16
+ <!-- Logo end -->
17
+ <div>
18
+ <div class="groupelementsnoline">
19
+ <h2>Telegenta Phone Client Demo</h2>
20
+ </div>
21
+ <div class="groupelements">
22
+ <h3>STEP 1: Get account list</h3>
23
+ <div class="inputelements">
24
+ <label for="api_key">API Key</label>
25
+ <input type="text" size="40" id="api_key" placeholder="Enter API Key" value="" />
26
+ <button onclick="populateSelectElements()">Get sip accounts</button>
27
+ </div>
28
+ </div>
29
+
30
+ <div class="groupelements">
31
+ <h3>STEP 2: Start phone</h3>
32
+ <div class="inputelements">
33
+ <label for="account_selector">SIP Accounts</label
34
+ ><span class="smallright"
35
+ ><small>Connection: <span id="conn_status">DISCONNECTED</span></small></span
36
+ >
37
+ <select id="account_selector">
38
+ <option value="" disabled selected>Waiting for SIP accounts</option>
39
+ </select>
40
+ <button onclick="startPhoneClient()">Start phone and use selected account</button>
41
+ <button onclick="stopPhoneClient()">Stop the phone client</button>
42
+ </div>
43
+ </div>
44
+
45
+ <div class="groupelements">
46
+ <h3>STEP 3: Add a new call</h3>
47
+ <div class="inputelements">
48
+ <label for="destination_number">Number to call</label
49
+ ><span class="smallright"
50
+ ><small
51
+ >Status: <span id="call_status">IDLE</span> &nbsp;| Duration:
52
+ <span id="call_duration">-</span></small
53
+ ></span
54
+ >
55
+ <input type="text" size="40" id="destination_number" placeholder="Enter phone number" value="" />
56
+ <button onclick="makeCall()">Call number now</button>
57
+ </div>
58
+ </div>
59
+
60
+ <div class="groupelements">
61
+ <h3>Transfer call</h3>
62
+
63
+ <div class="inputelements">
64
+ <h3 id="transfer_from"></h3>
65
+ <label for="transfer_selector">Select call: </label>
66
+ <select id="transfer_selector">
67
+ <option value="" disabled selected>No call to transfer</option>
68
+ </select>
69
+
70
+ <button onclick="doCallTransfer()">Transfer call</button>
71
+ </div>
72
+ </div>
73
+
74
+ <div class="groupelements">
75
+ <h3>Listen call</h3>
76
+
77
+ <div class="inputelements">
78
+ <h3>Listen to another call</h3>
79
+ <label for="listen_key">Call listen key</label>
80
+ <input type="text" size="40" id="listen_key" placeholder="Enter call listen key" value="" />
81
+ <button onclick="doListen()">Listen now</button>
82
+ </div>
83
+ </div>
84
+
85
+ <div class="groupelements">
86
+ <h3>Playback</h3>
87
+ <div class="inputelements">
88
+ <label for="media_file_selector">Media files</label>
89
+ <select id="media_file_selector">
90
+ <option value="" disabled selected>Select media file</option>
91
+ </select>
92
+ </div>
93
+ </div>
94
+
95
+ <div class="groupelementsnoline">
96
+ <h3>Active calls</h3>
97
+ <table id="session_table">
98
+ <tr>
99
+ <th>Direction</th>
100
+ <th>Destination number</th>
101
+ <th>State</th>
102
+ <th>Duration</th>
103
+ <th>Quality metrics</th>
104
+ <th>Mic muted</th>
105
+ <th>Recording</th>
106
+ <th>On hold</th>
107
+ <th>Actions</th>
108
+ </tr>
109
+ </table>
110
+ </div>
111
+ <div class="groupelementsnoline">
112
+ <small>Tip: Press F12 (developer console) to get additional information</small>
113
+ </div>
25
114
  </div>
26
- </div>
27
-
28
- <div class="groupelements">
29
- <H3>STEP 2: Start phone</H3>
30
- <div class="inputelements">
31
- <label for="account_selector">SIP Accounts</label><span class="smallright"><small>Connection: <span
32
- id="conn_status">DISCONNECTED</span></small></span>
33
- <select id="account_selector">
34
- <option value="" disabled selected>Waiting for SIP accounts</option>
35
- </select>
36
- <button onclick="startPhoneClient()">Start phone and use selected account</button>
37
- <button onclick="stopPhoneClient()">Stop the phone client</button>
38
- </div>
39
- </div>
40
-
41
- <div class="groupelements">
42
- <H3>STEP 3: Add a new call</H3>
43
- <div class="inputelements">
44
- <label for="destination_number">Number to call</label><span class="smallright"><small>Status: <span
45
- id="call_status">IDLE</span>
46
- &nbsp;| Duration: <span id="call_duration">-</span></small></span>
47
- <input type="text" size="40" id="destination_number" placeholder="Enter phone number" value="">
48
- <button onclick="makeCall()">Call number now</button>
49
- </div>
50
- </div>
115
+ </body>
116
+
117
+ <!-- Javascript stuff -->
118
+ <script>
119
+ const API_URL = 'https://api.telegenta.com/api';
120
+ let phoneClient = null;
121
+ let logger;
122
+ let transferSession;
123
+
124
+ // Start when DOM is ready
125
+ window.onload = function () {
126
+ // Create phone instance first
127
+ logger = new Telegenta.LogHandler(Telegenta.LOGLVL.DEBUG);
128
+ phoneClient = new Telegenta.Phone(logger);
129
+
130
+ // Check browser is supported first
131
+ if (!phoneClient.browserSupported) {
132
+ console.error('Your browser is not supported');
133
+ } else {
134
+ console.info('Your browser is supported');
135
+ }
136
+ };
137
+
138
+ /*
139
+ * STEP 1: Get a list of sip accounts from API server and populate select box with these accounts
140
+ */
141
+ function populateSelectElements() {
142
+ // SIP Accounts
143
+ jsonApiGetRequest('/sip-trunks/').then(
144
+ function (data) {
145
+ console.info(`Fetched ${data.results.length} sip accounts:`);
146
+ console.debug(data);
147
+
148
+ // Now reset and populate select box with accounts
149
+ document.getElementById('account_selector').innerHTML = '';
150
+ for (const account of data.results) {
151
+ document.getElementById('account_selector').appendChild(new Option(account.name, account.id));
152
+ }
153
+ },
154
+ function (reason) {
155
+ console.error(`Request failed ${reason}`);
156
+ },
157
+ );
158
+
159
+ // Media files
160
+ jsonApiGetRequest('/media-files/').then(
161
+ function (data) {
162
+ console.info(`Fetched ${data.results.length} media files:`);
163
+ console.debug(data);
164
+
165
+ // Now reset and populate select box with accounts
166
+ document.getElementById('media_file_selector').innerHTML = '';
167
+ for (const mfile of data.results) {
168
+ document.getElementById('media_file_selector').appendChild(new Option(mfile.name, mfile.id));
169
+ }
170
+ },
171
+ function (reason) {
172
+ console.error(`Request failed ${reason}`);
173
+ },
174
+ );
175
+ }
51
176
 
52
- <div class="groupelements">
53
- <H3>Transfer call</H3>
177
+ /*
178
+ * STEP 2: Get a new call_token from API and start phone client with account chosen in select box
179
+ */
180
+ function startPhoneClient() {
181
+ const accountId = document.getElementById('account_selector').value;
182
+ console.info(`Starting phone client with account id ${accountId}`);
183
+
184
+ // Create call session and get provision token
185
+ jsonApiGetRequest(`/get-call-session/?id=${accountId}`).then(
186
+ function (data) {
187
+ console.info('Fetched a new call session');
188
+ console.debug(data);
189
+
190
+ // Now prepare media and get access to microphone
191
+ phoneClient.prepareMedia().then(
192
+ function () {
193
+ // Media was prepared, now hook up events to display whats going on
194
+
195
+ // Connection state shows the client connection to the phone services
196
+ phoneClient.on('connectionStateChange', function (event) {
197
+ console.info(`Phone connection is now: ${event.state}`);
198
+ document.getElementById('conn_status').innerHTML = event.state;
199
+ });
200
+
201
+ // Get local information about call after it has ended
202
+ phoneClient.on('callEnded', function (data) {
203
+ console.info('Call ended event:');
204
+ console.info(data);
205
+ });
206
+
207
+ // Get remote information about call after it has ended
208
+ phoneClient.on('callDataInfo', function (data) {
209
+ console.info('Call data info event:');
210
+ console.info(data);
211
+ });
212
+
213
+ // New session created
214
+ phoneClient.on('sessionCreated', function (data) {
215
+ newSession(data.session);
216
+ });
217
+
218
+ // Session removed
219
+ phoneClient.on('sessionRemoved', function (data) {
220
+ console.log(data);
221
+ removeSession(data.session);
222
+ });
223
+
224
+ // Show incoming call
225
+ phoneClient.on('incomingCall', function (data) {
226
+ console.log(`Incoming call from ${data.originatingNumber}`);
227
+ });
228
+
229
+ // Now start phone with the following options
230
+ const opts = {
231
+ // Enable event client
232
+ connectEventService: true,
233
+
234
+ // Subscribe to detailed information about call after processing
235
+ useCallDataInfoEvent: true,
236
+
237
+ // Enable incoming calls (you must set a phone number to call the account also)
238
+ register: true,
239
+
240
+ // Configure client with provision token
241
+ provisionToken: data.provision_token,
242
+
243
+ // Enable signal tones (busy, invalid, etc)
244
+ playSignalTones: true,
245
+
246
+ // Enable call initialized tone
247
+ playCallInitializedTone: true,
248
+ };
249
+
250
+ try {
251
+ phoneClient.start(opts);
252
+ console.info('Media prepared and phone started');
253
+ } catch (e) {
254
+ console.error('Unable to start phone');
255
+ console.error(e);
256
+ }
257
+ },
258
+ function (reason) {
259
+ console.error('Unable to get media permission: ' + reason);
260
+ },
261
+ );
262
+ },
263
+ function (reason) {
264
+ console.error(`Request failed ${reason}`);
265
+ },
266
+ );
267
+ }
54
268
 
55
- <div class="inputelements">
56
- <h3 id="transfer_from"></h3>
57
- <label for="transfer_selector">Select call: </label>
58
- <select id="transfer_selector">
59
- <option value="" disabled selected>No call to transfer</option>
60
- </select>
269
+ // Stop phone client
270
+ function stopPhoneClient() {
271
+ phoneClient.stop();
272
+ }
61
273
 
62
- <button onclick="doCallTransfer()">Transfer call</button>
63
- </div>
64
- </div>
274
+ /*
275
+ * STEP 3: Make a test call
276
+ */
277
+ function makeCall() {
278
+ const destination_number = document.getElementById('destination_number').value;
279
+ phoneClient.call(destination_number, {
280
+ // Change this to number of days to keep recording (enables recording)
281
+ record: 0,
65
282
 
66
- <div class="groupelements">
67
- <H3>Listen call</H3>
283
+ // Change this maximum amount in customer currency the call must cost before hanging up (0 = no checking)
284
+ maximumCallCost: 0,
68
285
 
69
- <div class="inputelements">
70
- <h3>Listen to another call</h3>
71
- <label for="listen_key">Call listen key</label>
72
- <input type="text" size="40" id="listen_key" placeholder="Enter call listen key" value="">
73
- <button onclick="doListen()">Listen now</button>
74
- </div>
75
- </div>
76
-
77
- <div class="groupelements">
78
- <H3>Playback</H3>
79
- <div class="inputelements">
80
- <label for="media_file_selector">Media files</label>
81
- <select id="media_file_selector">
82
- <option value="" disabled selected>Select media file</option>
83
- </select>
84
- </div>
85
- </div>
86
-
87
- <div class="groupelementsnoline">
88
- <H3>Active calls</H3>
89
- <table id="session_table">
90
- <tr>
91
- <th>Direction</th>
92
- <th>Destination number</th>
93
- <th>State</th>
94
- <th>Duration</th>
95
- <th>Quality metrics</th>
96
- <th>Mic muted</th>
97
- <th>Recording</th>
98
- <th>On hold</th>
99
- <th>Actions</th>
100
- </tr>
101
- </table>
102
- </div>
103
- <div class="groupelementsnoline">
104
- <small>Tip: Press F12 (developer console) to get additional information</small>
105
- </div>
106
- </div>
107
- </body>
108
-
109
- <!-- Javascript stuff -->
110
- <script>
111
- const API_URL = 'https://api.telegenta.com/api';
112
- let phoneClient = null;
113
- let logger;
114
- let transferSession;
115
-
116
- // Start when DOM is ready
117
- window.onload = function () {
118
- // Create phone instance first
119
- logger = new Telegenta.Logger.LogHandler(Telegenta.Logger.LOGLVL.DEBUG);
120
- phoneClient = new Telegenta.Phone(logger);
121
-
122
- // Check browser is supported first
123
- if (!phoneClient.browserSupported) {
124
- console.error('Your browser is not supported');
125
- }
126
- };
127
-
128
-
129
- /*
130
- * STEP 1: Get a list of sip accounts from API server and populate select box with these accounts
131
- */
132
- function populateSelectElements() {
133
- // SIP Accounts
134
- jsonApiGetRequest('/sip-trunks/').then(function (data) {
135
- console.info(`Fetched ${data.results.length} sip accounts:`);
136
- console.debug(data);
137
-
138
- // Now reset and populate select box with accounts
139
- document.getElementById('account_selector').innerHTML = '';
140
- for (const account of data.results) {
141
- document.getElementById('account_selector').appendChild(new Option(account.name, account.id));
142
- }
143
- }, function (reason) {
144
- console.error(`Request failed ${reason}`);
145
- });
146
-
147
- // Media files
148
- jsonApiGetRequest('/media-files/').then(function (data) {
149
- console.info(`Fetched ${data.results.length} media files:`);
150
- console.debug(data);
151
-
152
- // Now reset and populate select box with accounts
153
- document.getElementById('media_file_selector').innerHTML = '';
154
- for (const mfile of data.results) {
155
- document.getElementById('media_file_selector').appendChild(new Option(mfile.name, mfile.id));
156
- }
157
- }, function (reason) {
158
- console.error(`Request failed ${reason}`);
159
- });
160
- }
161
-
162
- /*
163
- * STEP 2: Get a new call_token from API and start phone client with account chosen in select box
164
- */
165
- function startPhoneClient() {
166
- const accountId = document.getElementById('account_selector').value;
167
- console.info(`Starting phone client with account id ${accountId}`);
168
-
169
- // Create call session and get provision token
170
- jsonApiGetRequest(`/get-call-session/?id=${accountId}`).then(function (data) {
171
- console.info('Fetched a new call session');
172
- console.debug(data);
173
-
174
- // Now prepare media and get access to microphone
175
- phoneClient.prepareMedia().then(function () {
176
- // Media was prepared, now hook up events to display whats going on
177
-
178
- // Connection state shows the client connection to the phone services
179
- phoneClient.on('connectionStateChange', function (event) {
180
- console.info(`Phone connection is now: ${event.state}`);
181
- document.getElementById('conn_status').innerHTML = event.state;
182
- });
183
-
184
- // Get local information about call after it has ended
185
- phoneClient.on('callEnded', function (data) {
186
- console.info('Call ended event:');
187
- console.info(data);
188
- });
189
-
190
- // Get remote information about call after it has ended
191
- phoneClient.on('callDataInfo', function (data) {
192
- console.info('Call data info event:');
193
- console.info(data);
194
- });
195
-
196
- // New session created
197
- phoneClient.on('sessionCreated', function (data) {
198
- newSession(data.session);
199
- });
200
-
201
- // Session removed
202
- phoneClient.on('sessionRemoved', function (data) {
203
- console.log(data);
204
- removeSession(data.session);
205
- });
206
-
207
- // Show incoming call
208
- phoneClient.on('incomingCall', function (data) {
209
- console.log(`Incoming call from ${data.originatingNumber}`);
210
- });
211
-
212
- // Now start phone with the following options
213
- const opts = {
214
- // Enable event client
215
- connectEventService: true,
216
-
217
- // Subscribe to detailed information about call after processing
218
- useCallDataInfoEvent: true,
219
-
220
- // Enable incoming calls (you must set a phone number to call the account also)
221
- register: true,
222
-
223
- // Configure client with provision token
224
- provisionToken: data.provision_token,
225
-
226
- // Enable signal tones (busy, invalid, etc)
227
- playSignalTones: true,
228
-
229
- // Enable call initialized tone
230
- playCallInitializedTone: true
231
- };
286
+ // Include this to force a specific caller id (use id of phone number from api service)
287
+ // explicitCallerId: 35,
232
288
 
233
- try {
234
- phoneClient.start(opts);
235
- console.info('Media prepared and phone started');
236
- } catch (e) {
237
- console.error('Unable to start phone');
238
- console.error(e);
239
- }
240
- }, function (reason) {
241
- console.error('Unable to get media permission: ' + reason);
289
+ // Include this to force a specific smart cid (use id of shot-cid from api service)
290
+ // explicitShortCallerId: 1,
291
+
292
+ // Configure answer call timeout
293
+ answerCallTimeout: 0,
294
+
295
+ // Add meta info to call
296
+ metaInfo:
297
+ 'You can add up to 256 bytes of meta info for your call (including json like {"type": "json"})',
242
298
  });
243
- }, function (reason) {
244
- console.error(`Request failed ${reason}`);
245
- });
246
- }
247
-
248
- // Stop phone client
249
- function stopPhoneClient() {
250
- phoneClient.stop();
251
- }
252
-
253
- /*
254
- * STEP 3: Make a test call
255
- */
256
- function makeCall() {
257
- const destination_number = document.getElementById('destination_number').value;
258
- phoneClient.call(destination_number, {
259
- // Change this to number of days to keep recording (enables recording)
260
- record: 0,
261
-
262
- // Change this maximum amount in customer currency the call must cost before hanging up (0 = no checking)
263
- maximumCallCost: 0,
264
-
265
- // Include this to force a specific caller id (use id of phone number from api service)
266
- // explicitCallerId: 35,
267
-
268
- // Include this to force a specific smart cid (use id of shot-cid from api service)
269
- // explicitShortCallerId: 1,
270
-
271
- // Configure answer call timeout
272
- answerCallTimeout: 0,
273
-
274
- // Add meta info to call
275
- metaInfo: 'You can add up to 256 bytes of meta info for your call (including json like {"type": "json"})'
276
- });
277
- }
278
-
279
- // Set the source of call transfer and populate transfer destination selector
280
- function setTransferSession(session) {
281
- transferSession = session;
282
-
283
- var otherSessions = session.getOtherSessions();
284
- if (otherSessions.length < 1) {
285
- document.getElementById('transfer_from').innerHTML = 'Requires two active sessions to perform transfer!';
286
- return;
287
299
  }
288
300
 
289
- // Show source call destination number
290
- document.getElementById('transfer_from').innerHTML = session.destinationNumber + ' => ';
301
+ // Set the source of call transfer and populate transfer destination selector
302
+ function setTransferSession(session) {
303
+ transferSession = session;
291
304
 
292
- // Add all other sessions to transfer selector
293
- document.getElementById('transfer_selector').innerHTML = '';
305
+ var otherSessions = session.getOtherSessions();
306
+ if (otherSessions.length < 1) {
307
+ document.getElementById('transfer_from').innerHTML =
308
+ 'Requires two active sessions to perform transfer!';
309
+ return;
310
+ }
294
311
 
295
- for (const tSession of otherSessions) {
296
- document.getElementById('transfer_selector').appendChild(new Option(tSession.destinationNumber, tSession.uuid));
297
- }
298
- }
312
+ // Show source call destination number
313
+ document.getElementById('transfer_from').innerHTML = session.destinationNumber + ' => ';
299
314
 
300
- // Transfer call from "transferSession" to item in transfer_selector
301
- function doCallTransfer() {
302
- if (!transferSession) {
303
- console.error('No session selected');
304
- return;
305
- }
315
+ // Add all other sessions to transfer selector
316
+ document.getElementById('transfer_selector').innerHTML = '';
306
317
 
307
- // Use session uuid from selectbox and get session object
308
- const dstSession = phoneClient.getSessionByUUID(document.getElementById('transfer_selector').value);
309
-
310
- // Now do transfer
311
- transferSession.transfer(dstSession);
312
- }
313
-
314
- // Create listen session
315
- function doListen() {
316
- phoneClient.listen(document.getElementById('listen_key').value);
317
- }
318
-
319
- // Playback message
320
- function playback(session) {
321
- const hangup_after = false;
322
- session.playback(document.getElementById('media_file_selector').value, hangup_after).then(() => {
323
- console.info('Playback started');
324
- })
325
- }
326
-
327
- /*
328
- * Helper functions
329
- */
330
-
331
- // Create new session
332
- // Add table row for session using session_<uuid> as element id,
333
- // (We do this so we can find and remove row when session ends)
334
- function newSession(session) {
335
- const rowId = `session_${session.uuid}`;
336
-
337
- // Create row in table for session
338
- const table = document.getElementById("session_table");
339
- const newRow = table.insertRow();
340
- newRow.id = rowId;
341
- for (let i = 0; i < table.rows[0].cells.length; i++)
342
- newRow.insertCell();
343
-
344
- // Set cells
345
- newRow.cells[0].innerText = session.direction;
346
-
347
- // Show name of local number called for inbound
348
- if (session.localNumberName) {
349
- newRow.cells[1].innerText = session.destinationNumber + ' (' + session.localNumberName + ')';
350
- } else {
351
- newRow.cells[1].innerText = session.destinationNumber;
318
+ for (const tSession of otherSessions) {
319
+ document
320
+ .getElementById('transfer_selector')
321
+ .appendChild(new Option(tSession.destinationNumber, tSession.uuid));
322
+ }
352
323
  }
353
324
 
354
- // Hookup events
355
- // Session state show the current calling state
356
- session.on('sessionStateChange', function (event) {
357
- console.info(`Phone session is now: ${event.state}`);
358
- newRow.cells[2].innerHTML = event.state;
359
- // Add failure cause
360
- if (event.state === 'FAILED') {
361
- newRow.cells[2].innerHTML = newRow.cells[2].innerHTML + ` (${event.cause})`;
325
+ // Transfer call from "transferSession" to item in transfer_selector
326
+ function doCallTransfer() {
327
+ if (!transferSession) {
328
+ console.error('No session selected');
329
+ return;
362
330
  }
363
- updateButtons(newRow.cells[8], session);
364
- });
365
-
366
- // Get record state events
367
- newRow.cells[6].innerHTML = session.isRecording;
368
- session.on('recordingStateChange', function (data) {
369
- console.info(`Recording state changed to ${data.state}`);
370
- newRow.cells[6].innerHTML = data.state;
371
- });
372
-
373
- // Get mute state events
374
- newRow.cells[5].innerHTML = session.isMuted;
375
- session.on('muteStateChange', function (data) {
376
- console.info(`Microphone mute state changed to ${data.state}`);
377
- newRow.cells[5].innerHTML = data.state;
378
- });
379
-
380
- // Get hold state events
381
- newRow.cells[7].innerHTML = session.isOnHold;
382
- session.on('holdStateChange', function (data) {
383
- console.info(`Call hold state changed to ${data.state}`);
384
- newRow.cells[7].innerHTML = data.state;
385
- });
386
-
387
- // Get call duration update events
388
- session.on('callDurationUpdate', function (data) {
389
- newRow.cells[3].innerHTML = `${data.durationStr} (${data.activeDurationStr})`;
390
- });
391
-
392
- // Get call duration update events
393
- session.on('callQualityReportUpdate', function (data) {
394
- console.info('Call quality report:');
395
- console.info(data);
396
- newRow.cells[4].innerHTML = `${data.delta.effectiveLatency.toFixed(1)} ms (${data.delta.rFactor.toFixed(1)} R)`;
397
- });
398
-
399
- // Get local information about call after it has ended
400
- session.on('callEnded', function (data) {
401
- console.info('Call ended event:');
402
- console.debug(data);
403
- });
404
-
405
- session.on('whisperModeChange', function (data) {
406
- console.info('Whisper mode: ' + data.mode);
407
- });
408
-
409
- }
410
-
411
- // Remove table row for session
412
- function removeSession(session) {
413
- const row = document.getElementById(`session_${session.uuid}`);
414
- if (row) {
415
- row.parentNode.removeChild(row);
331
+
332
+ // Use session uuid from selectbox and get session object
333
+ const dstSession = phoneClient.getSessionByUUID(document.getElementById('transfer_selector').value);
334
+
335
+ // Now do transfer
336
+ transferSession.transfer(dstSession);
416
337
  }
417
- }
418
-
419
- // Add buttons based on session state on element (the table row)
420
- function updateButtons(element, session) {
421
- // Remove all buttons first
422
- let e = element.firstElementChild;
423
- while (e) {
424
- e.remove();
425
- e = element.firstElementChild;
338
+
339
+ // Create listen session
340
+ function doListen() {
341
+ phoneClient.listen(document.getElementById('listen_key').value);
426
342
  }
427
343
 
428
- // Put session on TD element, so buttons can use it
429
- element._session = session;
430
-
431
- // NON TERMINATED/INCOMING/FAILED BUTTONS
432
- if (session.state !== 'TERMINATED' && session.state !== 'INCOMING' && session.state !== 'FAILED') {
433
- const btn = document.createElement("BUTTON");
434
- btn.innerHTML = 'Hangup';
435
- btn.onclick = function () {
436
- this.parentNode._session.hangup();
437
- };
438
- element.appendChild(btn)
344
+ // Playback message
345
+ function playback(session) {
346
+ const hangup_after = false;
347
+ session.playback(document.getElementById('media_file_selector').value, hangup_after).then(() => {
348
+ console.info('Playback started');
349
+ });
439
350
  }
440
351
 
441
- if (session.direction === 'OUTBOUND' || session.direction === 'INBOUND') {
442
- // ACTIVE CALL BUTTONS
443
- if (session.state === 'ACTIVE' || session.state === 'ON_HOLD') {
444
- const btn = document.createElement("BUTTON");
445
- btn.innerHTML = 'Play tone';
446
- btn.onclick = function () {
447
- phoneClient.playTone(1000, 440, 880, function () {
448
- console.info('Play tone complete!')
449
- });
450
- };
451
- element.appendChild(btn);
352
+ /*
353
+ * Helper functions
354
+ */
355
+
356
+ // Create new session
357
+ // Add table row for session using session_<uuid> as element id,
358
+ // (We do this so we can find and remove row when session ends)
359
+ function newSession(session) {
360
+ const rowId = `session_${session.uuid}`;
361
+
362
+ // Create row in table for session
363
+ const table = document.getElementById('session_table');
364
+ const newRow = table.insertRow();
365
+ newRow.id = rowId;
366
+ for (let i = 0; i < table.rows[0].cells.length; i++) newRow.insertCell();
367
+
368
+ // Set cells
369
+ newRow.cells[0].innerText = session.direction;
370
+
371
+ // Show name of local number called for inbound
372
+ if (session.localNumberName) {
373
+ newRow.cells[1].innerText = session.destinationNumber + ' (' + session.localNumberName + ')';
374
+ } else {
375
+ newRow.cells[1].innerText = session.destinationNumber;
376
+ }
452
377
 
453
- const btn2 = document.createElement("BUTTON");
454
- btn2.innerHTML = 'Send DTMF 1';
455
- btn2.onclick = function () {
456
- this.parentNode._session.sendDTMF(1);
457
- };
458
- element.appendChild(btn2);
378
+ // Hookup events
379
+ // Session state show the current calling state
380
+ session.on('sessionStateChange', function (event) {
381
+ console.info(`Phone session is now: ${event.state}`);
382
+ newRow.cells[2].innerHTML = event.state;
383
+ // Add failure cause
384
+ if (event.state === 'FAILED') {
385
+ newRow.cells[2].innerHTML = newRow.cells[2].innerHTML + ` (${event.cause})`;
386
+ }
387
+ updateButtons(newRow.cells[8], session);
388
+ });
459
389
 
460
- const btn3 = document.createElement("BUTTON");
461
- btn3.innerHTML = 'Toggle mute mic';
462
- btn3.onclick = function () {
463
- this.parentNode._session.toggleMute();
464
- };
465
- element.appendChild(btn3);
390
+ // Get record state events
391
+ newRow.cells[6].innerHTML = session.isRecording;
392
+ session.on('recordingStateChange', function (data) {
393
+ console.info(`Recording state changed to ${data.state}`);
394
+ newRow.cells[6].innerHTML = data.state;
395
+ });
466
396
 
467
- const btn4 = document.createElement("BUTTON");
468
- btn4.innerHTML = 'Toggle recording';
469
- btn4.onclick = function () {
470
- this.parentNode._session.toggleRecording();
471
- };
472
- element.appendChild(btn4);
397
+ // Get mute state events
398
+ newRow.cells[5].innerHTML = session.isMuted;
399
+ session.on('muteStateChange', function (data) {
400
+ console.info(`Microphone mute state changed to ${data.state}`);
401
+ newRow.cells[5].innerHTML = data.state;
402
+ });
473
403
 
474
- const btn5 = document.createElement("BUTTON");
475
- btn5.innerHTML = 'Toggle hold';
476
- btn5.onclick = function () {
477
- this.parentNode._session.toggleHold();
478
- };
479
- element.appendChild(btn5);
404
+ // Get hold state events
405
+ newRow.cells[7].innerHTML = session.isOnHold;
406
+ session.on('holdStateChange', function (data) {
407
+ console.info(`Call hold state changed to ${data.state}`);
408
+ newRow.cells[7].innerHTML = data.state;
409
+ });
480
410
 
481
- const btn6 = document.createElement("BUTTON");
482
- btn6.innerHTML = 'Transfer';
483
- btn6.onclick = function () {
484
- setTransferSession(this.parentNode._session);
485
- };
486
- element.appendChild(btn6);
411
+ // Get call duration update events
412
+ session.on('callDurationUpdate', function (data) {
413
+ newRow.cells[3].innerHTML = `${data.durationStr} (${data.activeDurationStr})`;
414
+ });
415
+
416
+ // Get call duration update events
417
+ session.on('callQualityReportUpdate', function (data) {
418
+ console.info('Call quality report:');
419
+ console.info(data);
420
+ newRow.cells[4].innerHTML = `${data.delta.effectiveLatency.toFixed(1)} ms (${data.delta.rFactor.toFixed(
421
+ 1,
422
+ )} R)`;
423
+ });
424
+
425
+ // Get local information about call after it has ended
426
+ session.on('callEnded', function (data) {
427
+ console.info('Call ended event:');
428
+ console.debug(data);
429
+ });
430
+
431
+ session.on('whisperModeChange', function (data) {
432
+ console.info('Whisper mode: ' + data.mode);
433
+ });
434
+ }
435
+
436
+ // Remove table row for session
437
+ function removeSession(session) {
438
+ const row = document.getElementById(`session_${session.uuid}`);
439
+ if (row) {
440
+ row.parentNode.removeChild(row);
441
+ }
442
+ }
443
+
444
+ // Add buttons based on session state on element (the table row)
445
+ function updateButtons(element, session) {
446
+ // Remove all buttons first
447
+ let e = element.firstElementChild;
448
+ while (e) {
449
+ e.remove();
450
+ e = element.firstElementChild;
451
+ }
452
+
453
+ // Put session on TD element, so buttons can use it
454
+ element._session = session;
487
455
 
488
- const btn7 = document.createElement("BUTTON");
489
- btn7.innerHTML = 'Playback';
490
- btn7.onclick = function () {
491
- playback(this.parentNode._session);
456
+ // NON TERMINATED/INCOMING/FAILED BUTTONS
457
+ if (session.state !== 'TERMINATED' && session.state !== 'INCOMING' && session.state !== 'FAILED') {
458
+ const btn = document.createElement('BUTTON');
459
+ btn.innerHTML = 'Hangup';
460
+ btn.onclick = function () {
461
+ this.parentNode._session.hangup();
492
462
  };
493
- element.appendChild(btn7);
463
+ element.appendChild(btn);
494
464
  }
495
465
 
496
- // INCOMING BUTTONS
497
- if (session.state === 'INCOMING') {
498
- const btn = document.createElement("BUTTON");
499
- btn.innerHTML = 'Answer';
466
+ if (session.direction === 'OUTBOUND' || session.direction === 'INBOUND') {
467
+ // ACTIVE CALL BUTTONS
468
+ if (session.state === 'ACTIVE' || session.state === 'ON_HOLD') {
469
+ const btn = document.createElement('BUTTON');
470
+ btn.innerHTML = 'Play tone';
471
+ btn.onclick = function () {
472
+ phoneClient.playTone(1000, 440, 880, function () {
473
+ console.info('Play tone complete!');
474
+ });
475
+ };
476
+ element.appendChild(btn);
477
+
478
+ const btn2 = document.createElement('BUTTON');
479
+ btn2.innerHTML = 'Send DTMF 1';
480
+ btn2.onclick = function () {
481
+ this.parentNode._session.sendDTMF(1);
482
+ };
483
+ element.appendChild(btn2);
484
+
485
+ const btn3 = document.createElement('BUTTON');
486
+ btn3.innerHTML = 'Toggle mute mic';
487
+ btn3.onclick = function () {
488
+ this.parentNode._session.toggleMute();
489
+ };
490
+ element.appendChild(btn3);
491
+
492
+ const btn4 = document.createElement('BUTTON');
493
+ btn4.innerHTML = 'Toggle recording';
494
+ btn4.onclick = function () {
495
+ this.parentNode._session.toggleRecording();
496
+ };
497
+ element.appendChild(btn4);
498
+
499
+ const btn5 = document.createElement('BUTTON');
500
+ btn5.innerHTML = 'Toggle hold';
501
+ btn5.onclick = function () {
502
+ this.parentNode._session.toggleHold();
503
+ };
504
+ element.appendChild(btn5);
505
+
506
+ const btn6 = document.createElement('BUTTON');
507
+ btn6.innerHTML = 'Transfer';
508
+ btn6.onclick = function () {
509
+ setTransferSession(this.parentNode._session);
510
+ };
511
+ element.appendChild(btn6);
512
+
513
+ const btn7 = document.createElement('BUTTON');
514
+ btn7.innerHTML = 'Playback';
515
+ btn7.onclick = function () {
516
+ playback(this.parentNode._session);
517
+ };
518
+ element.appendChild(btn7);
519
+ }
520
+
521
+ // INCOMING BUTTONS
522
+ if (session.state === 'INCOMING') {
523
+ const btn = document.createElement('BUTTON');
524
+ btn.innerHTML = 'Answer';
525
+ btn.onclick = function () {
526
+ this.parentNode._session.answer(
527
+ (metaInfo = 'When answering calls you can add meta info as well'),
528
+ );
529
+ };
530
+ element.appendChild(btn);
531
+
532
+ const btn2 = document.createElement('BUTTON');
533
+ btn2.innerHTML = 'Reject';
534
+ btn2.onclick = function () {
535
+ this.parentNode._session.reject();
536
+ };
537
+ element.appendChild(btn2);
538
+ }
539
+ }
540
+
541
+ // LISTEN BUTTONS
542
+ if (session.direction === 'LISTEN' && session.state === 'ACTIVE') {
543
+ const btn = document.createElement('BUTTON');
544
+ btn.innerHTML = 'Start whisper';
500
545
  btn.onclick = function () {
501
- this.parentNode._session.answer(metaInfo = 'When answering calls you can add meta info as well');
546
+ this.parentNode._session.setWhisperMode(1);
502
547
  };
503
548
  element.appendChild(btn);
504
549
 
505
- const btn2 = document.createElement("BUTTON");
506
- btn2.innerHTML = 'Reject';
550
+ const btn2 = document.createElement('BUTTON');
551
+ btn2.innerHTML = 'End whisper';
507
552
  btn2.onclick = function () {
508
- this.parentNode._session.reject();
553
+ this.parentNode._session.setWhisperMode(0);
509
554
  };
510
555
  element.appendChild(btn2);
511
556
  }
512
557
  }
513
558
 
514
- // LISTEN BUTTONS
515
- if (session.direction === 'LISTEN' && session.state === 'ACTIVE') {
516
- const btn = document.createElement("BUTTON");
517
- btn.innerHTML = 'Start whisper';
518
- btn.onclick = function () {
519
- this.parentNode._session.setWhisperMode(1);
520
- };
521
- element.appendChild(btn);
522
-
523
- const btn2 = document.createElement("BUTTON");
524
- btn2.innerHTML = 'End whisper';
525
- btn2.onclick = function () {
526
- this.parentNode._session.setWhisperMode(0);
527
- };
528
- element.appendChild(btn2);
529
- }
530
- }
531
-
532
- // Perform authenticated ajax request to api server and return json payload on success
533
- function jsonApiGetRequest(path) {
534
- const xhr = new XMLHttpRequest();
535
- const url = API_URL + path;
536
- xhr.open('GET', url, true);
537
- xhr.responseType = 'json';
538
- const apiToken = document.getElementById('api_key').value;
539
- xhr.setRequestHeader('Authorization', 'Bearer ' + apiToken);
540
- xhr.setRequestHeader('Accept', 'application/json');
541
-
542
- return new Promise(function (resolve, reject) {
543
- xhr.onreadystatechange = function () {
544
- if (xhr.readyState === 4) {
545
- if (xhr.status !== 200) {
546
- reject(xhr.status + ' ' + xhr.statusText);
547
- return;
559
+ // Perform authenticated ajax request to api server and return json payload on success
560
+ function jsonApiGetRequest(path) {
561
+ const xhr = new XMLHttpRequest();
562
+ const url = API_URL + path;
563
+ xhr.open('GET', url, true);
564
+ xhr.responseType = 'json';
565
+ const apiToken = document.getElementById('api_key').value;
566
+ xhr.setRequestHeader('Authorization', 'Bearer ' + apiToken);
567
+ xhr.setRequestHeader('Accept', 'application/json');
568
+
569
+ return new Promise(function (resolve, reject) {
570
+ xhr.onreadystatechange = function () {
571
+ if (xhr.readyState === 4) {
572
+ if (xhr.status !== 200) {
573
+ reject(xhr.status + ' ' + xhr.statusText);
574
+ return;
575
+ }
576
+ resolve(xhr.response);
548
577
  }
549
- resolve(xhr.response);
550
- }
551
- };
552
- console.debug(`API Request: ${url}`);
553
- xhr.send();
554
- })
555
- }
556
- </script>
557
-
558
- </html>
578
+ };
579
+ console.debug(`API Request: ${url}`);
580
+ xhr.send();
581
+ });
582
+ }
583
+ </script>
584
+ </html>