podchat-browser 11.3.3 → 11.4.2

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.
@@ -191,6 +191,10 @@
191
191
  currentCallId = null,
192
192
  shouldReconnectCallTimeout = null,
193
193
  callTopics = {},
194
+ callMetaDataTypes = {
195
+ POORCONNECTION: 1,
196
+ POORCONNECTIONRESOLVED: 2
197
+ },
194
198
  screenShareState = {
195
199
  started: false,
196
200
  imOwner: false
@@ -488,172 +492,29 @@
488
492
  */
489
493
  startCallWebRTCFunctions = function (params, callback) {
490
494
  if (callDivId) {
491
- var callParentDiv,
492
- callVideo = (typeof params.video === 'boolean') ? params.video : true,
495
+ var callVideo = (typeof params.video === 'boolean') ? params.video : true,
493
496
  callMute = (typeof params.mute === 'boolean') ? params.mute : false;
494
- //sendingTopic = params.sendingTopic,
495
- //receiveTopic = params.receiveTopic;
497
+
498
+ if(params.selfData) {
499
+ callStateController.setupCallParticipant(params.selfData);
500
+ }
496
501
 
497
502
  if(params.clientsList && params.clientsList.length) {
498
503
  for(var i in params.clientsList) {
499
- callStateController.setupCallParticipant(params.clientsList[i]);
500
- //callStateController.callUsers.push(params.clientsList[i]);
504
+ if(params.clientsList[i].userId !== chatMessaging.userInfo.id)
505
+ callStateController.setupCallParticipant(params.clientsList[i]);
501
506
  }
502
507
  }
503
508
 
504
509
  callStateController.setupScreenSharingObject(params.screenShare);
505
510
 
506
- /*callTopics['sendVideoTopic'] = 'Vi-' + sendingTopic;
507
- callTopics['sendAudioTopic'] = 'Vo-' + sendingTopic;
508
- callTopics['screenShare'] = params.screenShare;
509
- //callTopics['receiveVideoTopic'] = 'Vi-' + receiveTopic;
510
- //callTopics['receiveAudioTopic'] = 'Vo-' + receiveTopic;
511
- callTopics['receive'] = [];
512
- callTopics['receive'].push({
513
- "VideoTopic": 'Vi-' + receiveTopic,
514
- "AudioTopic": 'Vo-' + receiveTopic
515
- });*/
516
-
517
- /*webpeersMetadata[callTopics['sendVideoTopic']] = {
518
- interval: null,
519
- receivedSdpAnswer: false,
520
- connectionQualityInterval: null,
521
- poorConnectionCount: 0,
522
- poorConnectionResolvedCount: 0,
523
- isConnectionPoor: false
524
- };
525
- webpeersMetadata[callTopics['sendAudioTopic']] = {
526
- interval: null,
527
- receivedSdpAnswer: false,
528
- connectionQualityInterval: null,
529
- poorConnectionCount: 0,
530
- poorConnectionResolvedCount: 0,
531
- isConnectionPoor: false
532
- };
533
- webpeersMetadata[callTopics['screenShare']] = {
534
- interval: null,
535
- receivedSdpAnswer: false,
536
- connectionQualityInterval: null,
537
- poorConnectionCount: 0,
538
- poorConnectionResolvedCount: 0,
539
- isConnectionPoor: false
540
- };
541
-
542
- for(var i in callTopics['receive']) {
543
- webpeersMetadata[callTopics['receive'][i]['VideoTopic']] = {
544
- interval: null,
545
- receivedSdpAnswer: false
546
- };
547
- webpeersMetadata[callTopics['receive'][i]['AudioTopic']] = {
548
- interval: null,
549
- receivedSdpAnswer: false
550
- };
551
- }*/
552
-
553
- //callParentDiv = document.getElementById(callDivId);
554
-
555
- /*// Local Video Tag
556
- if (callVideo && !uiRemoteMedias[callTopics['sendVideoTopic']]) {
557
- uiRemoteMedias[callTopics['sendVideoTopic']] = document.createElement('video');
558
- var el = uiRemoteMedias[callTopics['sendVideoTopic']];
559
- el.setAttribute('id', 'uiRemoteVideo-' + callTopics['sendVideoTopic']);
560
- el.setAttribute('class', callVideoTagClassName);
561
- el.setAttribute('playsinline', '');
562
- el.setAttribute('muted', '');
563
- el.setAttribute('width', callVideoMinWidth + 'px');
564
- el.setAttribute('height', callVideoMinHeight + 'px');
565
- }
566
-
567
- // Local Audio Tag
568
- if (!uiRemoteMedias[callTopics['sendAudioTopic']]) {
569
- uiRemoteMedias[callTopics['sendAudioTopic']] = document.createElement('audio');
570
- var el = uiRemoteMedias[callTopics['sendAudioTopic']];
571
- el.setAttribute('id', 'uiRemoteAudio-' + callTopics['sendAudioTopic']);
572
- el.setAttribute('class', callAudioTagClassName);
573
- el.setAttribute('autoplay', '');
574
- el.setAttribute('muted', '');
575
- el.setAttribute('controls', '');
576
- }
577
-
578
- for(var i in callTopics['receive']){
579
- // Remote Video Tag
580
- if (callVideo && !uiRemoteMedias[callTopics['receive'][i]['VideoTopic']]) {
581
- uiRemoteMedias[callTopics['receive'][i]['VideoTopic']] = document.createElement('video');
582
- var el = uiRemoteMedias[callTopics['receive'][i]['VideoTopic']];
583
- el.setAttribute('id', 'uiRemoteVideo-' + callTopics['receive'][i]['VideoTopic']);
584
- el.setAttribute('class', callVideoTagClassName);
585
- el.setAttribute('playsinline', '');
586
- el.setAttribute('muted', '');
587
- el.setAttribute('width', callVideoMinWidth + 'px');
588
- el.setAttribute('height', callVideoMinHeight + 'px');
589
- }
590
-
591
- // Remote Audio Tag
592
- if (!uiRemoteMedias[callTopics['receive'][i]['AudioTopic']]) {
593
- uiRemoteMedias[callTopics['receive'][i]['AudioTopic']] = document.createElement('audio');
594
- var el = uiRemoteMedias[callTopics['receive'][i]['AudioTopic']];
595
- el.setAttribute('id', 'uiRemoteAudio-' + callTopics['receive'][i]['AudioTopic']);
596
- el.setAttribute('class', callAudioTagClassName);
597
- el.setAttribute('autoplay', '');
598
- callMute && el.setAttribute('muted', '');
599
- el.setAttribute('controls', '');
600
- }
601
- }*/
602
-
603
511
  callback && callback(generateCallUIList());
604
512
 
605
- /*for(var i in callTopics['receive']) {
606
- uiRemoteElements.push(uiRemoteMedias[callTopics['receive'][i]['AudioTopic']])
607
- callVideo && uiRemoteElements.push(uiRemoteMedias[callTopics['receive'][i]['VideoTopic']])
608
- }
609
-
610
- if (callParentDiv) {
611
- callVideo && callParentDiv.appendChild(uiRemoteMedias[callTopics['sendVideoTopic']]);
612
- callParentDiv.appendChild(uiRemoteMedias[callTopics['sendAudioTopic']]);
613
- if(callVideo) {
614
- for(var i in callTopics['receive']) {
615
- callParentDiv.appendChild(uiRemoteMedias[callTopics['receive'][i]['VideoTopic']])
616
- }
617
- }
618
- for(var i in callTopics['receive']) {
619
- callParentDiv.appendChild(uiRemoteMedias[callTopics['receive'][i]['AudioTopic']]);
620
- }
621
-
622
- callback && callback({
623
- 'uiLocalVideo': uiRemoteMedias[callTopics['sendVideoTopic']],
624
- 'uiLocalAudio': uiRemoteMedias[callTopics['sendAudioTopic']],
625
- uiRemoteElements: uiRemoteElements
626
- /!* 'uiRemoteVideo': uiRemoteMedias[callTopics['receiveVideoTopic']],
627
- 'uiRemoteAudio': uiRemoteMedias[callTopics['receiveAudioTopic']]*!/
628
- });
629
- } else {
630
- callback && callback({
631
- 'uiLocalVideo': uiRemoteMedias[callTopics['sendVideoTopic']],
632
- 'uiLocalAudio': uiRemoteMedias[callTopics['sendAudioTopic']],
633
- uiRemoteElements: uiRemoteElements
634
- /!*'uiRemoteVideo': uiRemoteMedias[callTopics['receiveVideoTopic']],
635
- 'uiRemoteAudio': uiRemoteMedias[callTopics['receiveAudioTopic']]*!/
636
- });
637
- }*/
638
-
639
-
640
513
  callStateController.createSessionInChat(Object.assign(params, {
641
514
  callVideo: callVideo,
642
515
  callAudio: !callMute,
643
516
  }));
644
517
 
645
- /*sendCallMessage({
646
- id: 'STOPALL'
647
- }, function (result) {*/
648
-
649
- /*handleCallSocketOpen({
650
- brokerAddress: params.brokerAddress,
651
- turnAddress: params.turnAddress,
652
- callVideo: callVideo,
653
- callAudio: !callMute,
654
- });*/
655
-
656
- /* });*/
657
518
  } else {
658
519
  consoleLogging && console.log('No Call DIV has been declared!');
659
520
  return;
@@ -681,29 +542,6 @@
681
542
  };
682
543
  },
683
544
 
684
- /*handleCallSocketOpen = function (params) {
685
- currentCallParams = params;
686
-
687
- sendCallMessage({
688
- id: 'CREATE_SESSION',
689
- brokerAddress: params.brokerAddress,
690
- turnAddress: params.turnAddress.split(',')[0]
691
- }, function (res) {
692
- if (res.done === 'TRUE') {
693
- callStopQueue.callStarted = true;
694
- generateAndSendSdpOffers(params, [callTopics['sendVideoTopic'], callTopics['receiveVideoTopic'], callTopics['sendAudioTopic'], callTopics['receiveAudioTopic']]);
695
- } else if (res.done === 'SKIP') {
696
- callStopQueue.callStarted = true;
697
- generateAndSendSdpOffers(params, [callTopics['sendVideoTopic'], callTopics['receiveVideoTopic'], callTopics['sendAudioTopic'], callTopics['receiveAudioTopic']]);
698
- } else {
699
- consoleLogging && console.log('CREATE_SESSION faced a problem', res);
700
- endCall({
701
- callId: currentCallId
702
- });
703
- }
704
- });
705
- },*/
706
-
707
545
  callStateController = {
708
546
  createSessionInChat: function (params) {
709
547
  currentCallParams = params;
@@ -891,11 +729,33 @@
891
729
  * @param params
892
730
  * @param direction
893
731
  */
894
- removeParticipant: function (user) {
895
- if(user === chatMessaging.userInfo.id) {
896
- //TODO: only remove me
897
- callStop();
732
+ removeParticipant: function (userId) {
733
+ var user = callUsers[userId];
734
+ if(!user)
898
735
  return;
736
+
737
+ if(user.videoTopicName && user.peers[user.videoTopicName]) {
738
+ clearInterval(callUsers[userId].topicMetaData[user.videoTopicName].interval);
739
+ callStateController.removeConnectionQualityInterval(userId, user.videoTopicName);
740
+ callStateController.removeStreamFromWebRTC(userId, user.videoTopicName);
741
+ callUsers[userId].peers[user.videoTopicName].dispose();
742
+ delete callUsers[userId].peers[user.videoTopicName];
743
+
744
+ }
745
+ if(user.audioTopicName && user.peers[user.audioTopicName]) {
746
+ clearInterval(callUsers[userId].topicMetaData[user.audioTopicName].interval);
747
+ callStateController.removeConnectionQualityInterval(userId, user.audioTopicName);
748
+ callStateController.removeStreamFromWebRTC(userId, user.audioTopicName);
749
+
750
+ callUsers[userId].peers[user.audioTopicName].dispose();
751
+ delete callUsers[userId].peers[user.audioTopicName];
752
+ }
753
+
754
+ if(callUsers[userId]){
755
+ callUsers[userId].peers = {};
756
+ callUsers[userId].topicMetaData = {};
757
+ callUsers[userId].htmlElements = {};
758
+ callUsers[userId] = null;
899
759
  }
900
760
  },
901
761
  stopParticipantAudio: function (userId) {
@@ -921,8 +781,8 @@
921
781
  },
922
782
  removeTopic: function (userId, topic) {
923
783
  if(callUsers[userId].peers[topic]) {
924
- callUsers[userId].peers[topic].dispose();
925
784
  this.removeConnectionQualityInterval(userId, topic);
785
+ callUsers[userId].peers[topic].dispose();
926
786
  callUsers[userId].peers[topic] = null;
927
787
  }
928
788
  },
@@ -1028,7 +888,8 @@
1028
888
  message: 'Poor connection for a long time',
1029
889
  metadata: {
1030
890
  elementId: "uiRemoteVideo-" + topic,
1031
- topic: topic
891
+ topic: topic,
892
+ userId: userId
1032
893
  }
1033
894
  });
1034
895
  }
@@ -1048,6 +909,13 @@
1048
909
  userMetadata.isConnectionPoor = true;
1049
910
  userMetadata.poorConnectionCount = 0;
1050
911
  userMetadata.poorConnectionResolvedCount = 0;
912
+
913
+ sendCallMetaData({
914
+ id: callMetaDataTypes.POORCONNECTION,
915
+ userid: userId,
916
+ title: 'Poor Connection',
917
+ description: topic
918
+ });
1051
919
  } else {
1052
920
  callUsers[userId].topicMetaData[topic].poorConnectionCount++;
1053
921
  }
@@ -1061,9 +929,17 @@
1061
929
  message: 'Poor connection resolved',
1062
930
  metadata: {
1063
931
  elementId: "uiRemoteVideo-" + topic,
1064
- topic: topic
932
+ topic: topic,
933
+ userId: userId
1065
934
  }
1066
935
  });
936
+
937
+ sendCallMetaData({
938
+ id: callMetaDataTypes.POORCONNECTION,
939
+ userid: userId,
940
+ title: 'Poor Connection Resolved',
941
+ description: topic
942
+ });
1067
943
  } else {
1068
944
  userMetadata.poorConnectionResolvedCount++;
1069
945
  }
@@ -1144,12 +1020,12 @@
1144
1020
  errorInfo: user.peers[topic]
1145
1021
  });
1146
1022
  // setTimeout(function () {
1147
- if(chatMessaging.chatState) {
1148
- callController.shouldReconnectTopic(userId, topic, mediaType, direction);
1149
- }
1150
- // }, 7000);
1151
1023
 
1152
- callController.removeConnectionQualityInterval(userId, topic);
1024
+ if(chatMessaging.chatState) {
1025
+ callController.shouldReconnectTopic(userId, topic, mediaType, direction);
1026
+ }
1027
+ // }, 7000);
1028
+ //callController.removeConnectionQualityInterval(userId, topic);
1153
1029
  }
1154
1030
 
1155
1031
  if(user.peers[topic].peerConnection.connectionState === 'connected') {
@@ -1187,6 +1063,7 @@
1187
1063
  });
1188
1064
  if(chatMessaging.chatState) {
1189
1065
  callController.shouldReconnectTopic(userId, topic, mediaType, direction);
1066
+ //callController.removeConnectionQualityInterval(userId, topic);
1190
1067
  }
1191
1068
  // } else {
1192
1069
  // setTimeout(function () {
@@ -1226,9 +1103,11 @@
1226
1103
  topic: topic
1227
1104
  }, function (result) {
1228
1105
  if (result.done === 'TRUE') {
1106
+ clearInterval(callUsers[userId].topicMetaData[topic].interval)
1229
1107
  callController.removeTopic(userId, topic);
1230
1108
  callController.createTopic(userId, topic, mediaType, direction, userId === 'screenShare');
1231
1109
  } else if (result.done === 'SKIP') {
1110
+ clearInterval(callUsers[userId].topicMetaData[topic].interval)
1232
1111
  callController.removeTopic(userId, topic);
1233
1112
  callController.createTopic(userId, topic, mediaType, direction, userId === 'screenShare');
1234
1113
  //generateAndSendSdpOffers(currentCallParams, [topicName]);
@@ -1554,14 +1433,14 @@
1554
1433
  let newHeight = callVideoMinHeight - (Math.ceil(Math.random() * 50) + 20);
1555
1434
 
1556
1435
  videoTrack.applyConstraints({
1557
- width: {
1558
- min: newWidth,
1559
- ideal: 1280
1560
- },
1561
- height: {
1562
- min: newHeight,
1563
- ideal: 720
1564
- },
1436
+ // width: {
1437
+ // min: newWidth,
1438
+ // ideal: 1280
1439
+ // },
1440
+ // height: {
1441
+ // min: newHeight,
1442
+ // ideal: 720
1443
+ // },
1565
1444
  advanced: [
1566
1445
  {
1567
1446
  width: newWidth,
@@ -1627,6 +1506,12 @@
1627
1506
  }
1628
1507
  consoleLogging && console.log("[SDK][handleProcessSdpAnswer]", jsonMessage, jsonMessage.topic)
1629
1508
  startMedia(callUsers[userId].htmlElements[jsonMessage.topic]);
1509
+ if(userId === 'screenShare') {
1510
+ restartMediaOnKeyFrame("screenShare", 2000);
1511
+ restartMediaOnKeyFrame("screenShare", 4000);
1512
+ restartMediaOnKeyFrame("screenShare", 8000);
1513
+ restartMediaOnKeyFrame("screenShare", 12000);
1514
+ }
1630
1515
  });
1631
1516
  },
1632
1517
 
@@ -1699,47 +1584,102 @@
1699
1584
  currentCallId = null;
1700
1585
  },
1701
1586
 
1702
- removeStreamFromWebRTC = function (RTCStream) {
1703
- var callParentDiv = document.getElementById(callDivId);
1587
+ /*
1588
+ removeStreamFromWebRTC = function (RTCStream) {
1589
+ var callParentDiv = document.getElementById(callDivId);
1704
1590
 
1705
- if (uiRemoteMedias.hasOwnProperty(RTCStream)) {
1706
- const stream = uiRemoteMedias[RTCStream].srcObject;
1707
- if (!!stream) {
1708
- const tracks = stream.getTracks();
1591
+ if (uiRemoteMedias.hasOwnProperty(RTCStream)) {
1592
+ const stream = uiRemoteMedias[RTCStream].srcObject;
1593
+ if (!!stream) {
1594
+ const tracks = stream.getTracks();
1709
1595
 
1710
- if (!!tracks) {
1711
- tracks.forEach(function (track) {
1712
- track.stop();
1713
- });
1714
- }
1596
+ if (!!tracks) {
1597
+ tracks.forEach(function (track) {
1598
+ track.stop();
1599
+ });
1600
+ }
1715
1601
 
1716
- uiRemoteMedias[RTCStream].srcObject = null;
1717
- }
1602
+ uiRemoteMedias[RTCStream].srcObject = null;
1603
+ }
1718
1604
 
1719
- uiRemoteMedias[RTCStream].remove();
1720
- delete (uiRemoteMedias[RTCStream]);
1721
- }
1722
- },
1605
+ uiRemoteMedias[RTCStream].remove();
1606
+ delete (uiRemoteMedias[RTCStream]);
1607
+ }
1608
+ },
1723
1609
 
1724
- removeFromCallUI = function (topic) {
1725
- var videoElement = 'Vi-' + topic;
1726
- var audioElement = 'Vo-' + topic;
1727
1610
 
1728
- if (topic.length > 0 && uiRemoteMedias.hasOwnProperty(videoElement)) {
1729
- removeStreamFromWebRTC(videoElement);
1730
- }
1611
+ removeFromCallUI = function (topic) {
1612
+ var videoElement = 'Vi-' + topic;
1613
+ var audioElement = 'Vo-' + topic;
1731
1614
 
1732
- if (topic.length > 0 && uiRemoteMedias.hasOwnProperty(audioElement)) {
1733
- removeStreamFromWebRTC(audioElement);
1734
- }
1735
- },
1615
+ if (topic.length > 0 && uiRemoteMedias.hasOwnProperty(videoElement)) {
1616
+ removeStreamFromWebRTC(videoElement);
1617
+ }
1618
+
1619
+ if (topic.length > 0 && uiRemoteMedias.hasOwnProperty(audioElement)) {
1620
+ removeStreamFromWebRTC(audioElement);
1621
+ }
1622
+ },
1623
+ */
1736
1624
 
1737
1625
  restartMediaOnKeyFrame = function (userId, timeout) {
1738
1626
  setTimeout(function () {
1739
- if(typeof callUsers[chatMessaging.userInfo.id] !== "undefined" && callUsers[chatMessaging.userInfo.id])
1740
- restartMedia(callUsers[chatMessaging.userInfo.id].videoTopicName);
1627
+ if(typeof callUsers[userId] !== "undefined" && callUsers[userId] && callUsers[userId].peers[callUsers[userId].videoTopicName])
1628
+ restartMedia(callUsers[userId].videoTopicName);
1741
1629
  }, timeout);
1742
- };
1630
+ },
1631
+
1632
+ sendCallMetaData = function (params, callback) {
1633
+ var message = {
1634
+ id: params.id,
1635
+ userid: params.userid,
1636
+ title: params.title,
1637
+ description: params.description
1638
+ };
1639
+
1640
+ sendCallMessage({
1641
+ id: 'SENDMETADATA',
1642
+ message: JSON.stringify(message),
1643
+ chatId: currentCallId
1644
+ }, function (res) {
1645
+ callback && callback(res)
1646
+ });
1647
+ },
1648
+ handleReceivedMetaData = function (jsonMessage) {
1649
+ var id = jsonMessage.id;
1650
+ if(!id || typeof id === "undefined" || jsonMessage.userid === chatMessaging.userInfo.id) {
1651
+ return;
1652
+ }
1653
+
1654
+ switch (id) {
1655
+ case callMetaDataTypes.POORCONNECTION:
1656
+ chatEvents.fireEvent("callEvents", {
1657
+ type: 'POOR_VIDEO_CONNECTION',
1658
+ subType: 'SHORT_TIME',
1659
+ message: 'Poor connection detected',
1660
+ metadata: {
1661
+ elementId: "uiRemoteVideo-" + jsonMessage.description,
1662
+ topic: jsonMessage.description,
1663
+ userId: jsonMessage.userid
1664
+ }
1665
+ });
1666
+ break;
1667
+ case callMetaDataTypes.POORCONNECTIONRESOLVED:
1668
+ chatEvents.fireEvent('callEvents', {
1669
+ type: 'POOR_VIDEO_CONNECTION_RESOLVED',
1670
+ message: 'Poor connection resolved',
1671
+ metadata: {
1672
+ elementId: "uiRemoteVideo-" + jsonMessage.description,
1673
+ topic: jsonMessage.description,
1674
+ userId: jsonMessage.userid
1675
+ }
1676
+ });
1677
+ break;
1678
+ }
1679
+
1680
+ }
1681
+
1682
+
1743
1683
 
1744
1684
  this.updateToken = function (newToken) {
1745
1685
  token = newToken;
@@ -1764,26 +1704,21 @@
1764
1704
  break;
1765
1705
 
1766
1706
  case 'GET_KEY_FRAME':
1767
- restartMediaOnKeyFrame(chatMessaging.userInfo.id, 2000);
1768
- restartMediaOnKeyFrame(chatMessaging.userInfo.id, 4000);
1769
- restartMediaOnKeyFrame(chatMessaging.userInfo.id, 8000);
1770
- restartMediaOnKeyFrame(chatMessaging.userInfo.id, 12000);
1771
- /* setTimeout(function () {
1772
- if(typeof callUsers[chatMessaging.userInfo.id] === "undefined" || !callUsers[chatMessaging.userInfo.id])
1773
- restartMedia(callUsers[chatMessaging.userInfo.id].videoTopicName);
1774
- }, 2000);
1775
- setTimeout(function () {
1776
- if(typeof callUsers[chatMessaging.userInfo.id] === "undefined" || !callUsers[chatMessaging.userInfo.id])
1777
- restartMedia(callUsers[chatMessaging.userInfo.id].videoTopicName);
1778
- }, 4000);
1779
- setTimeout(function () {
1780
- if(typeof callUsers[chatMessaging.userInfo.id] === "undefined" || !callUsers[chatMessaging.userInfo.id])
1781
- restartMedia(callUsers[chatMessaging.userInfo.id].videoTopicName);
1782
- }, 8000);
1783
- setTimeout(function () {
1784
- if(typeof callUsers[chatMessaging.userInfo.id] === "undefined" || !callUsers[chatMessaging.userInfo.id])
1785
- restartMedia(callUsers[chatMessaging.userInfo.id].videoTopicName);
1786
- }, 12000);*/
1707
+ if(callUsers && callUsers[chatMessaging.userInfo.id] && callUsers[chatMessaging.userInfo.id].video) {
1708
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 2000);
1709
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 4000);
1710
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 8000);
1711
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 12000);
1712
+ }
1713
+ if(callUsers && callUsers['screenShare']
1714
+ && callUsers['screenShare'].video
1715
+ && screenShareState.started
1716
+ && screenShareState.imOwner) {
1717
+ restartMediaOnKeyFrame('screenShare', 2000);
1718
+ restartMediaOnKeyFrame('screenShare', 4000);
1719
+ restartMediaOnKeyFrame('screenShare', 8000);
1720
+ restartMediaOnKeyFrame('screenShare', 12000);
1721
+ }
1787
1722
  break;
1788
1723
 
1789
1724
  case 'FREEZED':
@@ -1795,11 +1730,13 @@
1795
1730
  chatMessaging.messagesCallbacks[uniqueId](jsonMessage);
1796
1731
  }
1797
1732
  break;*/
1733
+
1798
1734
  case 'STOP':
1799
1735
  if (chatMessaging.messagesCallbacks[uniqueId]) {
1800
1736
  chatMessaging.messagesCallbacks[uniqueId](jsonMessage);
1801
1737
  }
1802
1738
  break;
1739
+
1803
1740
  case 'CLOSE':
1804
1741
  if (chatMessaging.messagesCallbacks[uniqueId]) {
1805
1742
  chatMessaging.messagesCallbacks[uniqueId](jsonMessage);
@@ -1818,6 +1755,14 @@
1818
1755
  }
1819
1756
  break;
1820
1757
 
1758
+ case 'RECEIVEMETADATA':
1759
+ // if (chatMessaging.messagesCallbacks[uniqueId]) {
1760
+ // chatMessaging.messagesCallbacks[uniqueId](jsonMessage);
1761
+ // }
1762
+ handleReceivedMetaData(JSON.parse(jsonMessage.message));
1763
+
1764
+ break;
1765
+
1821
1766
  case 'ERROR':
1822
1767
  handleError(jsonMessage, params.sendingTopic, params.receiveTopic);
1823
1768
  break;
@@ -1864,7 +1809,7 @@
1864
1809
  result: messageContent
1865
1810
  });
1866
1811
 
1867
- currentCallId = messageContent.callId;
1812
+ //currentCallId = messageContent.callId;
1868
1813
 
1869
1814
  break;
1870
1815
 
@@ -1911,6 +1856,8 @@
1911
1856
  type: 'RECEIVE_CALL',
1912
1857
  result: messageContent
1913
1858
  });
1859
+
1860
+ currentCallId = messageContent.callId;
1914
1861
  } else {
1915
1862
  chatEvents.fireEvent('callEvents', {
1916
1863
  type: 'PARTNER_RECEIVED_YOUR_CALL',
@@ -1918,7 +1865,7 @@
1918
1865
  });
1919
1866
  }
1920
1867
 
1921
- currentCallId = messageContent.callId;
1868
+
1922
1869
 
1923
1870
  break;
1924
1871
 
@@ -1959,6 +1906,7 @@
1959
1906
  screenShare: messageContent.chatDataDto.screenShare,
1960
1907
  brokerAddress: messageContent.chatDataDto.brokerAddressWeb,
1961
1908
  turnAddress: messageContent.chatDataDto.turnAddress,
1909
+ selfData: messageContent.clientDTO,
1962
1910
  clientsList: messageContent.otherClientDtoList
1963
1911
  }, function (callDivs) {
1964
1912
  chatEvents.fireEvent('callEvents', {
@@ -2046,8 +1994,9 @@
2046
1994
  type: 'CALL_PARTICIPANT_CONNECTED',
2047
1995
  result: messageContent
2048
1996
  });
2049
-
2050
- restartMedia(callTopics['sendVideoTopic']);
1997
+ //callTopics['sendVideoTopic']
1998
+ //restartMedia(callUsers[chatMessaging.userInfo.id].videoTopicName);
1999
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 100)
2051
2000
 
2052
2001
  break;
2053
2002
 
@@ -2065,10 +2014,10 @@
2065
2014
  * Type 91 Send Group Call Request
2066
2015
  */
2067
2016
  case chatMessageVOTypes.GROUP_CALL_REQUEST:
2017
+ callRequestController.callRequestReceived = true;
2068
2018
  callReceived({
2069
2019
  callId: messageContent.callId
2070
- }, function (r) {
2071
- });
2020
+ }, function (r) {});
2072
2021
 
2073
2022
  if (chatMessaging.messagesCallbacks[uniqueId]) {
2074
2023
  chatMessaging.messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
@@ -2079,7 +2028,7 @@
2079
2028
  result: messageContent
2080
2029
  });
2081
2030
 
2082
- currentCallId = messageContent.callId;
2031
+ //currentCallId = messageContent.callId;
2083
2032
 
2084
2033
  break;
2085
2034
 
@@ -2096,9 +2045,16 @@
2096
2045
  result: messageContent
2097
2046
  });
2098
2047
 
2099
- if (!!messageContent[0].sendTopic) {
2100
- //removeFromCallUI(messageContent[0].sendTopic);
2101
- callStateController.removeFromCallUI(messageContent[0].sendTopic)
2048
+ if (!!messageContent[0].userId) {
2049
+ //callStateController.removeFromCallUI(messageContent[0].sendTopic)
2050
+ callStateController.removeParticipant(messageContent[0].userId);
2051
+ }
2052
+
2053
+ //If I'm the only call participant, stop the call
2054
+ if(callUsers) {
2055
+ if(Object.values(callUsers).length < 2) {
2056
+ callStop()
2057
+ }
2102
2058
  }
2103
2059
 
2104
2060
  break;
@@ -2120,14 +2076,36 @@
2120
2076
  if (chatMessaging.messagesCallbacks[uniqueId]) {
2121
2077
  chatMessaging.messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
2122
2078
  }
2079
+ if(Array.isArray(messageContent)) {
2080
+ for (var i in messageContent) {
2081
+ var correctedData = {
2082
+ video: messageContent[i].video,
2083
+ mute: messageContent[i].mute,
2084
+ userId: messageContent[i].userId,
2085
+ topicSend: messageContent[i].sendTopic
2086
+ }
2087
+ callStateController.setupCallParticipant(correctedData);
2088
+ if(correctedData.video) {
2089
+ callStateController.startParticipantVideo(correctedData.userId);
2090
+ }
2091
+ if(!correctedData.mute) {
2092
+ callStateController.startParticipantAudio(correctedData.userId);
2093
+ }
2094
+ }
2095
+ }
2096
+
2097
+ chatEvents.fireEvent('callEvents', {
2098
+ type: 'CALL_DIVS',
2099
+ result: generateCallUIList()
2100
+ });
2123
2101
 
2124
2102
  chatEvents.fireEvent('callEvents', {
2125
2103
  type: 'CALL_PARTICIPANT_JOINED',
2126
2104
  result: messageContent
2127
2105
  });
2128
2106
 
2129
- restartMedia(callTopics['sendVideoTopic']);
2130
-
2107
+ //restartMedia(callTopics['sendVideoTopic']);
2108
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 100)
2131
2109
  break;
2132
2110
 
2133
2111
  /**
@@ -2177,18 +2155,15 @@
2177
2155
  'audioTopicName',
2178
2156
  'mute'
2179
2157
  )
2180
- /*if(callUsers[messageContent[i].userId]) {
2181
- callUsers[messageContent[i].userId].mute = true;
2182
-
2183
- var user = callUsers[messageContent[i].userId];
2184
- clearInterval(callUsers[messageContent[i].userId].topicMetaData[user.audioTopicName].interval)
2185
- callStateController.removeTopic(messageContent[i].userId, user.audioTopicName);
2186
- callStateController.removeStreamFromWebRTC(messageContent[i].userId, user.audioTopicName);
2187
- }*/
2188
2158
  }
2189
2159
  }
2190
2160
  }
2191
2161
 
2162
+ chatEvents.fireEvent('callEvents', {
2163
+ type: 'CALL_DIVS',
2164
+ result: generateCallUIList()
2165
+ });
2166
+
2192
2167
  chatEvents.fireEvent('callEvents', {
2193
2168
  type: 'CALL_PARTICIPANT_MUTE',
2194
2169
  result: messageContent
@@ -2228,6 +2203,11 @@
2228
2203
  }
2229
2204
  }
2230
2205
 
2206
+ chatEvents.fireEvent('callEvents', {
2207
+ type: 'CALL_DIVS',
2208
+ result: generateCallUIList()
2209
+ });
2210
+
2231
2211
  chatEvents.fireEvent('callEvents', {
2232
2212
  type: 'CALL_PARTICIPANT_UNMUTE',
2233
2213
  result: messageContent
@@ -2277,16 +2257,6 @@
2277
2257
  messageContent[i].sendTopic,
2278
2258
  'video'
2279
2259
  );
2280
- /*if(callUsers[messageContent[i].userId]) {
2281
- callUsers[messageContent[i].userId].video = true;
2282
- callUsers[messageContent[i].userId].videoTopicName = 'Vi-' + messageContent[i].sendTopic;
2283
-
2284
- var user = callUsers[messageContent[i].userId];
2285
- callStateController.appendUserToCallDiv(messageContent[i].userId, callStateController.generateHTMLElements(messageContent[i].userId));
2286
- setTimeout(function () {
2287
- callStateController.createTopic(messageContent[i].userId, user.videoTopicName, 'video', 'receive');
2288
- })
2289
- }*/
2290
2260
  }
2291
2261
  }
2292
2262
  }
@@ -2319,13 +2289,6 @@
2319
2289
  'videoTopicName',
2320
2290
  'video'
2321
2291
  )
2322
- /* if(callUsers[messageContent[i].userId]) {
2323
- callUsers[messageContent[i].userId].video = false;
2324
- var user = callUsers[messageContent[i].userId];
2325
- clearInterval(callUsers[messageContent[i].userId].topicMetaData[user.videoTopicName].interval)
2326
- callStateController.removeTopic(messageContent[i].userId, user.videoTopicName);
2327
- callStateController.removeStreamFromWebRTC(messageContent[i].userId, user.videoTopicName);
2328
- }*/
2329
2292
  }
2330
2293
  }
2331
2294
  }
@@ -2357,7 +2320,15 @@
2357
2320
  result: messageContent
2358
2321
  });
2359
2322
 
2360
- restartMedia(callTopics['sendVideoTopic']);
2323
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 4000);
2324
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 8000);
2325
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 12000);
2326
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 25000);
2327
+
2328
+ restartMediaOnKeyFrame("screenShare", 4000);
2329
+ restartMediaOnKeyFrame("screenShare", 8000);
2330
+ restartMediaOnKeyFrame("screenShare", 12000);
2331
+ restartMediaOnKeyFrame("screenShare", 25000);
2361
2332
 
2362
2333
  break;
2363
2334
 
@@ -2454,7 +2425,15 @@
2454
2425
  result: messageContent
2455
2426
  });
2456
2427
 
2457
- restartMedia(callTopics['sendVideoTopic']);
2428
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 4000);
2429
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 8000);
2430
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 12000);
2431
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 25000);
2432
+
2433
+ restartMediaOnKeyFrame("screenShare", 4000);
2434
+ restartMediaOnKeyFrame("screenShare", 8000);
2435
+ restartMediaOnKeyFrame("screenShare", 12000);
2436
+ restartMediaOnKeyFrame("screenShare", 25000);
2458
2437
 
2459
2438
  break;
2460
2439
  }
@@ -2483,8 +2462,8 @@
2483
2462
 
2484
2463
  if (params.clientType
2485
2464
  && typeof params.clientType === 'string'
2486
- && callClientTypes[params.clientType.toUpperCase()] > 0) {
2487
- content.creatorClientDto.clientType = callClientTypes[params.clientType.toUpperCase()];
2465
+ && callClientType[params.clientType.toUpperCase()] > 0) {
2466
+ content.creatorClientDto.clientType = callClientType[params.clientType.toUpperCase()];
2488
2467
  } else {
2489
2468
  content.creatorClientDto.clientType = callClientType.WEB;
2490
2469
  }
@@ -2493,13 +2472,14 @@
2493
2472
  content.threadId = +params.threadId;
2494
2473
  } else {
2495
2474
  if (Array.isArray(params.invitees)) {
2496
- content.invitees = [];
2497
- for (var i = 0; i < params.invitees.length; i++) {
2498
- var tempInvitee = formatDataToMakeInvitee(params.invitees[i]);
2499
- if (tempInvitee) {
2500
- content.invitees.push(tempInvitee);
2501
- }
2502
- }
2475
+ content.invitees = params.invitees;
2476
+
2477
+ //for (var i = 0; i < params.invitees.length; i++) {
2478
+ //var tempInvitee = params.invitees[i];
2479
+ //if (tempInvitee) {
2480
+ //content.invitees.push(tempInvitee);
2481
+ //}
2482
+ //}
2503
2483
  } else {
2504
2484
  chatEvents.fireEvent('error', {
2505
2485
  code: 999,
@@ -2548,8 +2528,8 @@
2548
2528
 
2549
2529
  content.creatorClientDto.mute = (typeof params.mute === 'boolean') ? params.mute : false;
2550
2530
 
2551
- if (params.clientType && typeof params.clientType === 'string' && callClientTypes[params.clientType.toUpperCase()] > 0) {
2552
- content.creatorClientDto.clientType = callClientTypes[params.clientType.toUpperCase()];
2531
+ if (params.clientType && typeof params.clientType === 'string' && callClientType[params.clientType.toUpperCase()] > 0) {
2532
+ content.creatorClientDto.clientType = callClientType[params.clientType.toUpperCase()];
2553
2533
  } else {
2554
2534
  content.creatorClientDto.clientType = callClientType.WEB;
2555
2535
  }
@@ -2558,13 +2538,14 @@
2558
2538
  content.threadId = +params.threadId;
2559
2539
  } else {
2560
2540
  if (Array.isArray(params.invitees)) {
2561
- content.invitees = [];
2562
- for (var i = 0; i < params.invitees.length; i++) {
2563
- var tempInvitee = formatDataToMakeInvitee(params.invitees[i]);
2564
- if (tempInvitee) {
2565
- content.invitees.push(tempInvitee);
2566
- }
2567
- }
2541
+ content.invitees = params.invitees;
2542
+
2543
+ //for (var i = 0; i < params.invitees.length; i++) {
2544
+ //var tempInvitee = params.invitees[i];
2545
+ //if (tempInvitee) {
2546
+ //content.invitees.push(tempInvitee);
2547
+ //}
2548
+ //}
2568
2549
  } else {
2569
2550
  chatEvents.fireEvent('error', {
2570
2551
  code: 999,
@@ -2583,6 +2564,10 @@
2583
2564
  return;
2584
2565
  }
2585
2566
 
2567
+ callRequestController.cameraPaused = (typeof params.cameraPaused === 'boolean') ? params.cameraPaused : false;
2568
+ callRequestController.callRequestReceived = true;
2569
+ callRequestController.callEstablishedInMySide = true;
2570
+
2586
2571
  return chatMessaging.sendMessage(startCallData, {
2587
2572
  onResult: function (result) {
2588
2573
  callback && callback(result);
@@ -2654,8 +2639,8 @@
2654
2639
 
2655
2640
  callRequestController.cameraPaused = (typeof params.cameraPaused === 'boolean') ? params.cameraPaused : callRequestController.cameraPaused;
2656
2641
 
2657
- if (params.clientType && typeof params.clientType === 'string' && callClientTypes[params.clientType.toUpperCase()] > 0) {
2658
- content.clientType = callClientTypes[params.clientType.toUpperCase()];
2642
+ if (params.clientType && typeof params.clientType === 'string' && callClientType[params.clientType.toUpperCase()] > 0) {
2643
+ content.clientType = callClientType[params.clientType.toUpperCase()];
2659
2644
  } else {
2660
2645
  content.clientType = callClientType.WEB;
2661
2646
  }
@@ -2747,7 +2732,8 @@
2747
2732
 
2748
2733
  return chatMessaging.sendMessage(recordCallData, {
2749
2734
  onResult: function (result) {
2750
- restartMedia(callTopics['sendVideoTopic']);
2735
+ //restartMedia(callTopics['sendVideoTopic']);
2736
+ restartMediaOnKeyFrame(chatMessaging.userInfo.id, 100)
2751
2737
  callback && callback(result);
2752
2738
  }
2753
2739
  });
@@ -3201,10 +3187,6 @@
3201
3187
  'audioTopicName',
3202
3188
  'mute'
3203
3189
  )
3204
- /*
3205
- callStateController.removeTopic(chatMessaging.userInfo.id, callUsers[chatMessaging.userInfo.id].audioTopicName)
3206
- callStateController.removeStreamFromWebRTC(chatMessaging.userInfo.id, callUsers[chatMessaging.userInfo.id].audioTopicName)
3207
- */
3208
3190
 
3209
3191
  return chatMessaging.sendMessage(sendMessageParams, {
3210
3192
  onResult: function (result) {
@@ -3256,16 +3238,6 @@
3256
3238
  callUsers[myId].topicSend,
3257
3239
  'mute'
3258
3240
  );
3259
- /*if(callUsers[myId]) {
3260
- callUsers[myId].mute = false;
3261
- callUsers[myId].audioTopicName = 'Vo-' + callUsers[myId].topicSend;
3262
-
3263
- var user = callUsers[myId];
3264
- callStateController.appendUserToCallDiv(myId, callStateController.generateHTMLElements(myId));
3265
- setTimeout(function () {
3266
- callStateController.createTopic(myId, user.audioTopicName, 'audio', 'send');
3267
- })
3268
- }*/
3269
3241
 
3270
3242
  return chatMessaging.sendMessage(sendMessageParams, {
3271
3243
  onResult: function (result) {