@exotel-npm-dev/webrtc-client-sdk 1.0.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.
@@ -0,0 +1,644 @@
1
+ import { diagnosticsCallback } from "../../listeners/Callback";
2
+ import { webrtcLogger } from "./WebrtcLogger"
3
+
4
+ var webrtcSIPPhone = require('@exotel-npm-dev/webrtc-core-sdk/src/webrtcSIPPhone').webrtcSIPPhone;
5
+ var logger = webrtcLogger()
6
+ var speakerNode;
7
+ var micNode;
8
+ var audioTrack;
9
+ var thisBrowserName = "";
10
+ var intervalID;
11
+
12
+ var speakerTestTone = document.createElement("audio");
13
+ var eventMapper = { sipml5: {}, sipjs: {} };
14
+ eventMapper.sipjs.started = "WS_TEST_PASS";
15
+ eventMapper.sipjs.failed_to_start = "WS_TEST_FAIL";
16
+ eventMapper.sipjs.transport_error = "WS_TEST_FAIL";
17
+ eventMapper.sipjs.connected_REGISTER = "USER_REG_TEST_PASS";
18
+ eventMapper.sipjs.terminated_REGISTER = "USER_REG_TEST_FAIL";
19
+
20
+ eventMapper.sipml5.started = "WS_TEST_PASS";
21
+ eventMapper.sipml5.failed_to_start = "WS_TEST_FAIL";
22
+ eventMapper.sipml5.transport_error = "WS_TEST_FAIL";
23
+ eventMapper.sipml5.connected_REGISTER = "USER_REG_TEST_PASS";
24
+ eventMapper.sipml5.terminated_REGISTER = "USER_REG_TEST_FAIL";
25
+
26
+ var candidateProcessData = {};
27
+
28
+ export var ameyoWebRTCTroubleshooter = {
29
+ js_yyyy_mm_dd_hh_mm_ss: function () {
30
+ var now = new Date();
31
+ var year = "" + now.getFullYear();
32
+ var month = "" + (now.getMonth() + 1);
33
+ if (month.length == 1) {
34
+ month = "0" + month;
35
+ }
36
+ var day = "" + now.getDate();
37
+ if (day.length == 1) {
38
+ day = "0" + day;
39
+ }
40
+ var hour = "" + now.getHours();
41
+ if (hour.length == 1) {
42
+ hour = "0" + hour;
43
+ }
44
+ var minute = "" + now.getMinutes();
45
+ if (minute.length == 1) {
46
+ minute = "0" + minute;
47
+ }
48
+ var second = "" + now.getSeconds();
49
+ if (second.length == 1) {
50
+ second = "0" + second;
51
+ }
52
+ return (
53
+ year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second
54
+ );
55
+ },
56
+
57
+ addToTrobuleshootReport: function (type, message) {
58
+ var timestamp = this.js_yyyy_mm_dd_hh_mm_ss();
59
+ //window.loggingInLocalStorage(type,message);
60
+ var msg =
61
+ "[" +
62
+ timestamp +
63
+ "] " +
64
+ "[" +
65
+ type +
66
+ "] TROUBLESHOOTER_FSM_REPORT: " +
67
+ message +
68
+ "\n";
69
+ //if(window.addLogToTroubleshootReport) {
70
+ //this.addLogToTroubleshootReport
71
+ logger.log(msg);
72
+ var oldMsg = window.localStorage.getItem('troubleShootReport')
73
+ if (oldMsg) {
74
+ msg = oldMsg + msg
75
+ }
76
+ window.localStorage.setItem('troubleShootReport', msg)
77
+ diagnosticsCallback.triggerDiagnosticsSaveCallback('troubleShootReport', msg)
78
+ //}
79
+ },
80
+
81
+ getBrowserData: function () {
82
+ var agent = navigator.userAgent;
83
+ var browserName = navigator.appName;
84
+ var version = "" + parseFloat(navigator.appVersion);
85
+ var offsetName;
86
+ var offsetVersion;
87
+ var ix;
88
+ if ((offsetVersion = agent.indexOf("Edge")) !== -1) {
89
+ browserName = "Microsoft Edge";
90
+ version = agent.substring(offsetVersion + 5);
91
+ } else if ((offsetVersion = agent.indexOf("Chrome")) !== -1) {
92
+ browserName = "Chrome";
93
+ version = agent.substring(offsetVersion + 7);
94
+ } else if ((offsetVersion = agent.indexOf("MSIE")) !== -1) {
95
+ browserName = "Microsoft Internet Explorer"; // Older IE versions.
96
+ version = agent.substring(offsetVersion + 5);
97
+ } else if ((offsetVersion = agent.indexOf("Trident")) !== -1) {
98
+ browserName = "Microsoft Internet Explorer"; // Newer IE versions.
99
+ version = agent.substring(offsetVersion + 8);
100
+ } else if ((offsetVersion = agent.indexOf("Firefox")) !== -1) {
101
+ browserName = "Firefox";
102
+ version = agent.substring(offsetVersion + 8);
103
+ } else if ((offsetVersion = agent.indexOf("Safari")) !== -1) {
104
+ browserName = "Safari";
105
+ version = agent.substring(offsetVersion + 7);
106
+ if ((offsetVersion = agent.indexOf("Version")) !== -1) {
107
+ version = agent.substring(offsetVersion + 8);
108
+ }
109
+ } else if (
110
+ (offsetName = agent.lastIndexOf(" ") + 1) <
111
+ (offsetVersion = agent.lastIndexOf("/"))
112
+ ) {
113
+ // For other browsers 'name/version' is at the end of userAgent
114
+ browserName = agent.substring(offsetName, offsetVersion);
115
+ version = agent.substring(offsetVersion + 1);
116
+ if (browserName.toLowerCase() === browserName.toUpperCase()) {
117
+ browserName = navigator.appName;
118
+ }
119
+ } // Trim the version string at semicolon/space if present.
120
+ if ((ix = version.indexOf(";")) !== -1) {
121
+ version = version.substring(0, ix);
122
+ }
123
+ if ((ix = version.indexOf(" ")) !== -1) {
124
+ version = version.substring(0, ix);
125
+ }
126
+
127
+ this.addToTrobuleshootReport(
128
+ "INFO",
129
+ "Browser: " +
130
+ browserName +
131
+ "/" +
132
+ version +
133
+ ", Platform: " +
134
+ navigator.platform
135
+ );
136
+ thisBrowserName = browserName;
137
+ if (browserName == "Chrome") {
138
+ this.setDeviceNames();
139
+ }
140
+ return browserName + "/" + version;
141
+ },
142
+
143
+ stopSpeakerTesttone: function () {
144
+ speakerTestTone = webrtcSIPPhone.getSpeakerTestTone();
145
+ speakerTestTone.pause();
146
+ },
147
+
148
+ stopSpeakerTesttoneWithSuccess: function () {
149
+ this.stopSpeakerTest();
150
+ this.sendDeviceTestingEvent("SPEAKER_TEST_PASS");
151
+ this.addToTrobuleshootReport("INFO", "Speaker device testing is successfull");
152
+ this.addToTrobuleshootReport("INFO", "Speaker device testing is completed");
153
+ },
154
+
155
+ stopSpeakerTesttoneWithFailure: function () {
156
+ this.stopSpeakerTest();
157
+ this.sendDeviceTestingEvent("SPEAKER_TEST_FAIL");
158
+ this.addToTrobuleshootReport("INFO", "Speaker device testing is failed");
159
+ this.addToTrobuleshootReport("INFO", "Speaker device testing is completed");
160
+ },
161
+
162
+ startSpeakerTest: function () {
163
+ var parent = this;
164
+
165
+ try {
166
+ intervalID = setInterval(function(){
167
+
168
+ try {
169
+ speakerTestTone = webrtcSIPPhone.getSpeakerTestTone();
170
+ /* Close last pending tracks.. */
171
+ logger.log("close last track")
172
+ speakerTestTone.pause();
173
+ parent.closeAudioTrack();
174
+
175
+ parent.addToTrobuleshootReport("INFO", "Speaker device testing is started");
176
+ logger.log("speakerTestTone : play start", speakerTestTone);
177
+
178
+ speakerTestTone.addEventListener("ended", function(event) {
179
+ logger.log("speakerTestTone : tone iteration ended");
180
+ });
181
+
182
+ logger.log("start new track")
183
+
184
+ var playPromise = speakerTestTone.play();
185
+
186
+ if (playPromise !== undefined) {
187
+ playPromise.then(_ => {
188
+ logger.log("speakerTestTone : promise successfull");
189
+ })
190
+ .catch(error => {
191
+ // Auto-play was prevented
192
+ // Show paused UI.
193
+ logger.log("speakerTestTone : failed" , error) ;
194
+ });
195
+ }
196
+
197
+ var stream;
198
+ var browserVersion;
199
+ var browserName;
200
+
201
+ try {
202
+ browserVersion = parent.getBrowserData();
203
+ browserName = browserVersion.trim().split('/')[0];
204
+ } catch {
205
+ browserName = "Firefox"
206
+ }
207
+ logger.log("browserVersion = [" + browserVersion + "] browserName = [" + browserName + "]\n")
208
+
209
+ if (browserName == "Firefox") {
210
+ stream = speakerTestTone.mozCaptureStream();
211
+ } else {
212
+ stream = speakerTestTone.captureStream();
213
+ }
214
+ parent.fillStreamSpeaker(stream, "speaker");
215
+ } catch {
216
+ logger.log("No speakertone to test..\n")
217
+ }
218
+ //Enable this for tone loop - Start
219
+ }, 1000)
220
+ } catch (e) {
221
+ logger.log("speakerTestTone : start failed" , e) ;
222
+ }
223
+ //Enable this for tone loop - End
224
+
225
+ },
226
+
227
+ stopSpeakerTest: function () {
228
+ var parent = this;
229
+ speakerTestTone = webrtcSIPPhone.getSpeakerTestTone();
230
+ //Enable this for tone loop - Start
231
+ try {
232
+ clearInterval(intervalID)
233
+ intervalID = 0
234
+ //Enable this for tone loop - End
235
+ speakerTestTone.pause();
236
+ parent.closeAudioTrack();
237
+ parent.addToTrobuleshootReport("INFO", "Speaker device testing is stopped");
238
+ //Enable this for tone loop - Start
239
+ } catch (e) {
240
+ logger.log("speakerTestTone : stop failed" , e) ;
241
+ }
242
+ //Enable this for tone loop - End
243
+ },
244
+
245
+ startMicTest: function () {
246
+ this.closeAudioTrack();
247
+ this.addToTrobuleshootReport(
248
+ "INFO",
249
+ "Microphone device testing is inprogress"
250
+ );
251
+ var constraints = { audio: true, video: false };
252
+ var parent = this;
253
+
254
+ navigator.mediaDevices
255
+ .getUserMedia(constraints)
256
+ .then(function (mediaStream) {
257
+ var tracks = mediaStream.getTracks();
258
+ for (let i = 0; i < tracks.length; i++) {
259
+ var track = tracks[i];
260
+ parent.addToTrobuleshootReport(
261
+ "INFO",
262
+ "Device track settings: " +
263
+ "len: " +
264
+ tracks.length +
265
+ ", id:" +
266
+ track.getSettings().deviceId +
267
+ ", kind: " +
268
+ track.kind +
269
+ ", label:" +
270
+ track.label
271
+ );
272
+ //parent.setMicName(track.label);
273
+ if (thisBrowserName != "Chrome") {
274
+ //parent.setSpeakerName("Default");
275
+ }
276
+ audioTrack = track;
277
+ }
278
+ parent.fillStreamMicrophone(mediaStream, "mic");
279
+ })
280
+ .catch(function (error) {
281
+ parent.addToTrobuleshootReport(
282
+ "WARNING",
283
+ "Microphone device testing failed"
284
+ );
285
+ parent.sendDeviceTestingEvent("MICROPHONE_TEST_FAIL");
286
+ parent.addToTrobuleshootReport(
287
+ "WARNING",
288
+ "Error: " + error.message + ", name: " + error.name
289
+ );
290
+ });
291
+ },
292
+
293
+ stopMicTest: function () {
294
+ this.closeAudioTrack();
295
+ this.addToTrobuleshootReport("INFO", "Mic device testing is stopped");
296
+ },
297
+
298
+ stopMicTestSuccess: function () {
299
+ this.closeAudioTrack();
300
+ this.addToTrobuleshootReport(
301
+ "INFO",
302
+ "Microphone device testing is successful"
303
+ );
304
+ this.sendDeviceTestingEvent("MICROPHONE_TEST_PASS");
305
+ this.addToTrobuleshootReport("INFO", "Mic device testing is completed");
306
+ },
307
+
308
+ stopMicTestFailure: function () {
309
+ this.closeAudioTrack();
310
+ this.addToTrobuleshootReport(
311
+ "INFO",
312
+ "Microphone device testing is failure"
313
+ );
314
+ this.sendDeviceTestingEvent("MICROPHONE_TEST_FAIL");
315
+ this.addToTrobuleshootReport("INFO", "Mic device testing is failure");
316
+ this.addToTrobuleshootReport("INFO", "Mic device testing is completed");
317
+ },
318
+
319
+ setDeviceNames: function () {
320
+ if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
321
+ this.addToTrobuleshootReport("INFO", "enumerateDevices() not supported.");
322
+ return;
323
+ }
324
+ var mediaDeviceId;
325
+ var parent = this;
326
+ navigator.mediaDevices
327
+ .enumerateDevices()
328
+ .then(function (deviceInfos) {
329
+ for (let i = 0; i !== deviceInfos.length; ++i) {
330
+ parent.addToTrobuleshootReport(
331
+ "INFO",
332
+ "Device: " +
333
+ deviceInfos[i].kind +
334
+ ", label: " +
335
+ deviceInfos[i].label +
336
+ ", id:" +
337
+ deviceInfos[i].deviceId
338
+ );
339
+ if (deviceInfos[i].deviceId == "default") {
340
+ if (deviceInfos[i].kind == "audiooutput") {
341
+ var speakerName = deviceInfos[i].label;
342
+ diagnosticsCallback.triggerKeyValueSetCallback("speakerInfo", deviceInfos[i].label, "speakerInfo")
343
+ } else if (deviceInfos[i].kind == "audioinput") {
344
+ var micName = deviceInfos[i].label;
345
+ diagnosticsCallback.triggerKeyValueSetCallback("micInfo", deviceInfos[i].label, "micInfo")
346
+ }
347
+ }
348
+ }
349
+ })
350
+ .catch(function (error) {
351
+ parent.addToTrobuleshootReport(
352
+ "INFO",
353
+ "Error: " + error.message + ", name: " + error.name
354
+ );
355
+ });
356
+ },
357
+
358
+ closeAudioTrack: function () {
359
+ logger.log("In close audio track..")
360
+ if (audioTrack) {
361
+ audioTrack.stop();
362
+ audioTrack = undefined;
363
+ }
364
+ if (micNode) {
365
+ micNode.disconnect();
366
+ micNode = undefined;
367
+ }
368
+ if (speakerNode) {
369
+ speakerNode.disconnect();
370
+ speakerNode = undefined;
371
+ }
372
+ },
373
+
374
+ fillStreamMicrophone: function (stream, outDevice) {
375
+ try {
376
+ var audioContext = new AudioContext();
377
+ var analyser = audioContext.createAnalyser();
378
+ var source = audioContext.createMediaStreamSource(stream);
379
+ micNode = audioContext.createScriptProcessor(2048, 1, 1);
380
+ analyser.smoothingTimeConstant = 0.8;
381
+ analyser.fftSize = 1024;
382
+ source.connect(analyser);
383
+ analyser.connect(micNode);
384
+ micNode.connect(audioContext.destination);
385
+ micNode.onaudioprocess = function () {
386
+ var array = new Uint8Array(analyser.frequencyBinCount);
387
+ analyser.getByteFrequencyData(array);
388
+ var values = 0;
389
+ var length = array.length;
390
+ for (var i = 0; i < length; i++) {
391
+ values += array[i];
392
+ }
393
+ var average = values / length;
394
+ //diagnosticsCallback.triggerDiagnosticsMicStatusCallback(average, "mic ok");
395
+ diagnosticsCallback.triggerKeyValueSetCallback("mic", average, "mic ok")
396
+ if (average > 9) {
397
+ //fillMicColors(Math.round(average));
398
+ }
399
+ };
400
+ } catch (e) {
401
+ logger.log("Media source not available for mic test ..")
402
+ average = 0;
403
+ //diagnosticsCallback.triggerDiagnosticsMicStatusCallback(average, "mic error");
404
+ diagnosticsCallback.triggerKeyValueSetCallback("mic", average, "mic error")
405
+ }
406
+ },
407
+
408
+ fillStreamSpeaker: function (stream, outDevice) {
409
+ try {
410
+ var audioContext = new AudioContext();
411
+ var analyser = audioContext.createAnalyser();
412
+ var source = audioContext.createMediaStreamSource(stream);
413
+ speakerNode = audioContext.createScriptProcessor(2048, 1, 1);
414
+ analyser.smoothingTimeConstant = 0.8;
415
+ analyser.fftSize = 1024;
416
+ source.connect(analyser);
417
+ analyser.connect(speakerNode);
418
+ speakerNode.connect(audioContext.destination);
419
+ speakerNode.onaudioprocess = function () {
420
+ var array = new Uint8Array(analyser.frequencyBinCount);
421
+ analyser.getByteFrequencyData(array);
422
+ var values = 0;
423
+ var length = array.length;
424
+ for (var i = 0; i < length; i++) {
425
+ values += array[i];
426
+ }
427
+ var average = values / length;
428
+ diagnosticsCallback.triggerKeyValueSetCallback("speaker", average, "speaker ok");
429
+ };
430
+ } catch (e) {
431
+ logger.log("Media source not available for speaker test ..")
432
+ average = 0;
433
+ diagnosticsCallback.triggerKeyValueSetCallback("speaker", average, "speaker error");
434
+ }
435
+ },
436
+
437
+ setUserRegTroubleshootData: function(txtUser) {
438
+ logger.log("No explicit registration sent during testing...")
439
+ },
440
+
441
+ setWSTroubleshootData: function(txtWsStatus) {
442
+ //Already done during init, no need to do again.
443
+ let txtWSSUrl = webrtcSIPPhone.getWSSUrl();
444
+ diagnosticsCallback.triggerKeyValueSetCallback("wss", txtWsStatus, txtWSSUrl)
445
+ },
446
+
447
+ startWSAndUserRegistrationTest: function () {
448
+ try {
449
+ this.startNetworkProtocolTest();
450
+ } catch (e) {
451
+ logger.log(e);
452
+ }
453
+ },
454
+
455
+ sendEventToWebRTCTroubleshooter: function (eventType, sipMethod) {
456
+ if (sipMethod == "CONNECTION") {
457
+ eventType = eventType + "_" + sipMethod;
458
+ }
459
+
460
+ if (eventMapper.hasOwnProperty(webRTCPhoneEngine)) {
461
+ this.addToTrobuleshootReport("INFO", "WebRTCPhoneEvent " + eventType);
462
+ var mapper = eventMapper[webRTCPhoneEngine];
463
+ if (mapper.hasOwnProperty(eventType)) {
464
+ this.sendNetworkTestingEvent(mapper[eventType]);
465
+ this.addToTrobuleshootReport(
466
+ "INFO",
467
+ "TroubleshooterEvent " + mapper[eventType]
468
+ );
469
+ }
470
+ }
471
+ },
472
+
473
+ noop: function () {},
474
+
475
+ sendNetworkTestingEvent: function (event) {
476
+ this.addToTrobuleshootReport("INFO", "NETWORK EVENT = " + event);
477
+ },
478
+
479
+ sendDeviceTestingEvent: function (event) {
480
+ this.addToTrobuleshootReport("INFO", "DEVICE EVENT = " + event);
481
+ },
482
+
483
+ setTroubleshootCandidateData: function (key, status, value) {
484
+ logger.log(
485
+ "Candidate Data \n\t key = " + key + " status = " + status + "\n\tValue = " + value + "\n\n"
486
+ );
487
+ diagnosticsCallback.triggerKeyValueSetCallback(key, status, value);
488
+ },
489
+
490
+ startCandidatesForTroubleshoot: function () {
491
+ var keys = ["udp", "tcp", "ipv6", "host", "srflx"];
492
+ for (var j = 0; j < keys.length; j++) {
493
+ var key = keys[j];
494
+ this.setTroubleshootCandidateData(key, "waiting", "");
495
+ }
496
+ },
497
+
498
+ proccessCandidatesForTroubleshoot: function (candidates) {
499
+ candidateProcessData = {
500
+ udp: false,
501
+ udpCandidates: [],
502
+ tcp: false,
503
+ tcpCandidates: [],
504
+ ipv6: false,
505
+ ipv6Candidates: [],
506
+ host: false,
507
+ hostCandidates: [],
508
+ srflx: false,
509
+ srflxCandidates: [],
510
+ };
511
+
512
+ var keys = ["udp", "tcp", "ipv6", "host", "srflx"];
513
+ var success_status = ["connected", "connected", "connected", "connected", "connected"];
514
+ var failure_status = ["disconnected", "disconnected", "disconnected", "disconnected", "disconnected"];
515
+
516
+ for (var i = 0; i < candidates.length; i++) {
517
+ var candidate = candidates[i].candidate;
518
+ this.addToTrobuleshootReport("INFO", "Gathered candidate " + candidate);
519
+ var candidateData = candidate.split(" ");
520
+ var protocolType = candidateData[2];
521
+ var candidateType = candidateData[7];
522
+ var address = candidateData[4];
523
+
524
+ if (protocolType == "udp" || protocolType == "UDP") {
525
+ candidateProcessData.udp = true;
526
+ candidateProcessData.udpCandidates.push(candidate);
527
+ if (candidate.length > 0) {
528
+ this.sendNetworkTestingEvent("UDP_TEST_COMPLETE");
529
+ }
530
+ } else if (protocolType == "tcp" || protocolType == "TCP") {
531
+ candidateProcessData.tcp = true;
532
+ candidateProcessData.tcpCandidates.push(candidate);
533
+ this.sendNetworkTestingEvent("TCP_TEST_COMPLETE");
534
+ }
535
+
536
+ try {
537
+ if (address.includes(":") || address.includes("-") ) {
538
+ candidateProcessData.ipv6 = true;
539
+ candidateProcessData.ipv6Candidates.push(candidate);
540
+ this.sendNetworkTestingEvent("IPV6_TEST_COMPLETE");
541
+ }
542
+ } catch (e) {
543
+ this.sendNetworkTestingEvent("IPV6_TEST_COMPLETE");
544
+ }
545
+
546
+ if (candidateType == "host") {
547
+ candidateProcessData.host = true;
548
+ candidateProcessData.hostCandidates.push(candidate);
549
+ this.sendNetworkTestingEvent("HOST_CON_TEST_COMPLETE");
550
+ } else if (candidateType == "srflx") {
551
+ candidateProcessData.srflx = true;
552
+ candidateProcessData.srflxCandidates.push(candidate);
553
+ this.sendNetworkTestingEvent("REFLEX_CON_TEST_COMPLETE");
554
+ }
555
+ }
556
+
557
+
558
+ for (var j = 0; j < keys.length; j++) {
559
+ var key = keys[j];
560
+ if (candidateProcessData.hasOwnProperty(key)) {
561
+ var candidates = candidateProcessData[key + "Candidates"];
562
+ if (candidates.length == 0) {
563
+ this.setTroubleshootCandidateData(key, failure_status[j], "");
564
+ logger.log("empty candidates:" + candidates);
565
+ } else {
566
+ var cmsg = "found candidates " + candidates.length + "\n";
567
+ for (var k = 0; k < candidates.length; k++) {
568
+ this.setTroubleshootCandidateData(key, success_status[j], candidates[k]);
569
+ cmsg = cmsg + candidates[k] + "\n";
570
+ }
571
+ logger.log(cmsg);
572
+ }
573
+ }
574
+ }
575
+
576
+ },
577
+
578
+ isCandidateGathered: function (type) {
579
+ if (candidateProcessData.hasOwnProperty(type)) {
580
+ if (candidateProcessData[type]) {
581
+ return true;
582
+ } else {
583
+ return false;
584
+ }
585
+ } else {
586
+ return false;
587
+ }
588
+ },
589
+
590
+ startNetworkProtocolTest: function () {
591
+ var parent = this;
592
+ this.sendNetworkTestingEvent("UDP_TEST_STARTING");
593
+ this.sendNetworkTestingEvent("TCP_TEST_STARTING");
594
+ this.sendNetworkTestingEvent("IPV6_TEST_STARTING");
595
+ this.sendNetworkTestingEvent("HOST_CON_TEST_STARTING");
596
+ this.sendNetworkTestingEvent("REFLEX_CON_TEST_STARTING");
597
+ this.addToTrobuleshootReport("INFO", "Gathering ICE candidates ");
598
+
599
+ this.startCandidatesForTroubleshoot()
600
+
601
+ var configuration = {
602
+ iceServers: [
603
+ {
604
+ url: "stun:stun.l.google.com:19302",
605
+ },
606
+ ],
607
+ };
608
+ var pc = new RTCPeerConnection(configuration);
609
+ var candidates = [];
610
+
611
+ pc.addEventListener("icecandidate", function (e) {
612
+ if (e.candidate) {
613
+ candidates.push(e.candidate);
614
+ }
615
+ });
616
+
617
+ pc.addEventListener("iceconnectionstatechange", function (e) {
618
+ logger.log("ice connection state: " + pc.iceConnectionState);
619
+ });
620
+
621
+ pc.addEventListener("icegatheringstatechange", function (e) {
622
+ parent.setWSTroubleshootData('connected');
623
+
624
+ parent.addToTrobuleshootReport(
625
+ "INFO",
626
+ "ice gathering state: " + e.target.iceGatheringState
627
+ );
628
+
629
+ if (e.target.iceGatheringState == "complete") {
630
+ parent.proccessCandidatesForTroubleshoot(candidates);
631
+ if (pc) {
632
+ pc.close();
633
+ }
634
+ }
635
+ });
636
+
637
+ var createOfferParams = { offerToReceiveAudio: 1 };
638
+ pc.createOffer(createOfferParams).then(function (offer) {
639
+ pc.setLocalDescription(offer).then(parent.noop, parent.noop);
640
+ }, parent.noop);
641
+ },
642
+ };
643
+
644
+ //ameyoWebRTCTroubleshooter.getBrowserData();