@flashphoner/websdk 2.0.208 → 2.0.209

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashphoner/websdk",
3
- "version": "2.0.208",
3
+ "version": "2.0.209",
4
4
  "description": "Official Flashphoner WebCallServer WebSDK package",
5
5
  "main": "./src/flashphoner-core.js",
6
6
  "types": "./src/flashphoner-core.d.ts",
@@ -179,7 +179,10 @@ export function createSession(options: {
179
179
  custom?: any | undefined;
180
180
  sipOptions?: any | undefined;
181
181
  mediaOptions?: any | undefined;
182
- timeout?: any | undefined;
182
+ timeout?: number | undefined;
183
+ pingInterval?: number | undefined;
184
+ receiveProbes?: number | undefined;
185
+ probesInterval?: number | undefined;
183
186
  }): Session;
184
187
  export function playFirstSound (noise?: boolean): any;
185
188
  export function playFirstVideo (display: any, isLocal: boolean, src: any): any;
@@ -403,6 +403,9 @@ var getSession = function (id) {
403
403
  * @param {Object=} options.sipOptions Sip configuration
404
404
  * @param {Object=} options.mediaOptions Media connection configuration
405
405
  * @param {Integer=} options.timeout Connection timeout in milliseconds
406
+ * @param {Integer=} options.pingInterval Server ping interval in milliseconds [0]
407
+ * @param {Integer=} options.receiveProbes A maximum subsequental pings received missing count [0]
408
+ * @param {Integer=} options.probesInterval Interval to check subsequental pings received [0]
406
409
  * @returns {Session} Created session
407
410
  * @throws {Error} Error if API is not initialized
408
411
  * @throws {TypeError} Error if options.urlServer is not specified
@@ -427,6 +430,8 @@ var createSession = function (options) {
427
430
  var mediaOptions = options.mediaOptions;
428
431
  var keepAlive = options.keepAlive;
429
432
  var timeout = options.timeout;
433
+ var wsPingSender = new WSPingSender(options.pingInterval || 0);
434
+ var wsPingReceiver = new WSPingReceiver(options.receiveProbes || 0, options.probesInterval || 0);
430
435
  var connectionTimeout;
431
436
 
432
437
  var cConfig;
@@ -534,7 +539,7 @@ var createSession = function (options) {
534
539
  mediaProviders: Object.keys(MediaProvider),
535
540
  keepAlive: keepAlive,
536
541
  authToken:authToken,
537
- clientVersion: "2.0.208",
542
+ clientVersion: "2.0.209",
538
543
  clientOSVersion: window.navigator.appVersion,
539
544
  clientBrowserVersion: window.navigator.userAgent,
540
545
  msePacketizationVersion: 2,
@@ -546,6 +551,10 @@ var createSession = function (options) {
546
551
  //connect to REST App
547
552
  send("connection", cConfig);
548
553
  logger.setConnection(wsConnection);
554
+ // Send ping messages to server to check if connection is still alive #WCS-3410
555
+ wsPingSender.start();
556
+ // Check subsequintel pings received from server to check if connection is still alive #WCS-3410
557
+ wsPingReceiver.start();
549
558
  };
550
559
  wsConnection.onmessage = function (event) {
551
560
  var data = {};
@@ -558,6 +567,7 @@ var createSession = function (options) {
558
567
  switch (data.message) {
559
568
  case 'ping':
560
569
  send("pong", null);
570
+ wsPingReceiver.success();
561
571
  break;
562
572
  case 'getUserData':
563
573
  authToken = obj.authToken;
@@ -684,6 +694,10 @@ var createSession = function (options) {
684
694
  function onSessionStatusChange(newStatus, obj) {
685
695
  sessionStatus = newStatus;
686
696
  if (sessionStatus == SESSION_STATUS.DISCONNECTED || sessionStatus == SESSION_STATUS.FAILED) {
697
+ // Stop pinging server #WCS-3410
698
+ wsPingSender.stop();
699
+ // Stop checking pings received #WCS-3410
700
+ wsPingReceiver.stop();
687
701
  //remove streams
688
702
  for (var prop in streamRefreshHandlers) {
689
703
  if (streamRefreshHandlers.hasOwnProperty(prop) && typeof streamRefreshHandlers[prop] === 'function') {
@@ -698,6 +712,65 @@ var createSession = function (options) {
698
712
  }
699
713
  }
700
714
 
715
+ // Websocket periodic ping sender
716
+ function WSPingSender(interval) {
717
+ this.interval = interval || 0;
718
+ this.intervalId = null;
719
+ this.start = function() {
720
+ if (this.interval > 0) {
721
+ this.intervalId = setInterval(function() {
722
+ send("ping", null);
723
+ }, this.interval);
724
+ }
725
+ };
726
+ this.stop = function() {
727
+ if (this.intervalId) {
728
+ clearInterval(this.intervalId);
729
+ }
730
+ };
731
+
732
+ return(this);
733
+ }
734
+
735
+ // Websocket ping receive prober
736
+ function WSPingReceiver(receiveProbes, probesInterval) {
737
+ this.maxPings = receiveProbes || 0;
738
+ this.interval = probesInterval || 0;
739
+ this.intervalId = null;
740
+ this.pingsMissing = 0;
741
+ this.start = function() {
742
+ if (this.maxPings > 0 && this.interval > 0) {
743
+ let receiver = this;
744
+ this.intervalId = setInterval(function() {
745
+ receiver.checkPingsReceived();
746
+ }, this.interval);
747
+ }
748
+ };
749
+ this.stop = function() {
750
+ if (this.intervalId) {
751
+ clearInterval(this.intervalId);
752
+ }
753
+ this.pingsMissing = 0;
754
+ };
755
+ this.checkPingsReceived = function() {
756
+ this.pingsMissing++;
757
+ if (this.pingsMissing >= this.maxPings) {
758
+ this.failure();
759
+ }
760
+ };
761
+ this.success = function() {
762
+ this.pingsMissing = 0;
763
+ };
764
+ this.failure = function() {
765
+ logger.info(LOG_PREFIX, "Missing " + this.pingsMissing + " pings from server, connection seems to be down");
766
+ onSessionStatusChange(SESSION_STATUS.FAILED);
767
+ wsConnection.close();
768
+ };
769
+
770
+ return(this);
771
+ }
772
+
773
+
701
774
  /**
702
775
  * @callback sdpHook
703
776
  * @param {Object} sdp Callback options