|
240 | 240 | ) { |
241 | 241 | app.helpers.renderUsers.condition.page += 1; |
242 | 242 | ui.insertOccupants(false).then(function(users) { |
243 | | - app.users += users; |
| 243 | + var ids = users.map(function (user) { |
| 244 | + return user.id; |
| 245 | + }); |
| 246 | + app.users = users.concat(app.users.filter(function (item) { |
| 247 | + return ids.indexOf(item.id) < 0; |
| 248 | + })); |
244 | 249 | app.helpers.setFooterPosition(); |
245 | 250 | }, function() { |
246 | 251 | app.helpers.setFooterPosition(); |
|
433 | 438 | video: false |
434 | 439 | }; |
435 | 440 | document.querySelector('.j-actions[data-call="video"]').setAttribute('hidden', true); |
436 | | - document.querySelector('.j-caller__ctrl').setAttribute('hidden', true); |
437 | 441 | } else { |
438 | 442 | document.querySelector('.j-actions[data-call="audio"]').setAttribute('hidden', true); |
439 | 443 | } |
|
496 | 500 | notification_type: 'push', |
497 | 501 | user: {ids: pushRecipients}, |
498 | 502 | environment: 'development', // environment, can be 'production' as well. |
499 | | - message: QB.pushnotifications.base64Encode(app.caller.full_name + ' is calling you') |
| 503 | + message: QB.pushnotifications.base64Encode(JSON.stringify({ |
| 504 | + "message": app.caller.full_name + " is calling you", |
| 505 | + "ios_voip": "1", |
| 506 | + "VOIPCall":"1" |
| 507 | + })) |
500 | 508 | }; |
501 | 509 | // |
502 | 510 | QB.pushnotifications.events.create(params, function(err, response) { |
|
538 | 546 | video: false |
539 | 547 | }; |
540 | 548 | document.querySelector('.j-actions[data-call="video"]').setAttribute('hidden', true); |
541 | | - document.querySelector('.j-caller__ctrl').setAttribute('hidden', true); |
542 | 549 | } else { |
543 | 550 | mediaParams = { |
544 | 551 | audio: { |
|
640 | 647 |
|
641 | 648 | if( app.currentSession.peerConnections[userId].stream && !$that.srcObject ) { |
642 | 649 | if( $that.hasClass('active') ) { |
643 | | - $that.removeClass('active'); |
644 | | - |
645 | | - app.currentSession.detachMediaStream('main_video'); |
646 | | - app.helpers.changeFilter('#main_video', 'no'); |
647 | | - app.mainVideo = 0; |
648 | | - remoteStreamCounter = 0; |
| 650 | + return false; |
649 | 651 | } else { |
650 | | - $('.j-callees__callee_video').removeClass('active'); |
| 652 | + |
| 653 | + if(recorder) { |
| 654 | + recorder.stop(); |
| 655 | + } |
| 656 | + |
| 657 | + $('.j-callees__callee__video').removeClass('active'); |
651 | 658 | $that.addClass('active'); |
652 | 659 |
|
653 | 660 | app.helpers.changeFilter('#main_video', 'no'); |
|
665 | 672 | } |
666 | 673 | }); |
667 | 674 |
|
668 | | - $(document).on('click', '.j-caller__ctrl[data-target="screen"]', function(e, track) { |
669 | | - |
670 | | - var $btn = $(this), |
671 | | - isActive = $btn.hasClass('active'), |
672 | | - callMethod = (isActive)?'getUserMedia':'getDisplayMedia'; |
| 675 | + $(document).on('click', '.j-caller__ctrl[data-target="screen"]', function() { |
673 | 676 |
|
674 | | - if( _.isEmpty( app.currentSession)) { |
| 677 | + if( _.isEmpty(app.currentSession)) { |
675 | 678 | return false; |
676 | 679 | } |
677 | 680 |
|
678 | | - if(track) { |
679 | | - |
680 | | - app.currentSession.localStream.getVideoTracks()[0].stop(); |
681 | | - var stream = app.currentSession.localStream.clone(); |
682 | | - stream.removeTrack(stream.getVideoTracks()[0]); |
683 | | - stream.addTrack(track); |
684 | | - app.currentSession.localStream.getAudioTracks()[0].stop(); |
685 | | - app.currentSession._replaceTracks(stream); |
686 | | - app.currentSession.localStream = stream; |
687 | | - |
688 | | - if(isActive) { |
689 | | - $btn.removeClass('active'); |
690 | | - } else { |
691 | | - $btn.addClass('active'); |
692 | | - } |
| 681 | + var $btn = $(this), |
| 682 | + isActive = $btn.hasClass('active'), |
| 683 | + runScreenSharing = function(){ |
| 684 | + navigator.mediaDevices.getDisplayMedia({ |
| 685 | + video: true, |
| 686 | + }).then(stream => { |
| 687 | + var videoTrack = stream.getVideoTracks()[0]; |
| 688 | + videoTrack.onended = stopScreenSharing; |
| 689 | + switchMediaTrack(videoTrack); |
| 690 | + $btn.addClass('active'); |
| 691 | + }); |
| 692 | + }, |
| 693 | + stopScreenSharing = function(){ |
| 694 | + navigator.mediaDevices.getUserMedia({ |
| 695 | + video: true, |
| 696 | + }).then(stream => { |
| 697 | + switchMediaTrack(stream.getVideoTracks()[0]); |
| 698 | + $btn.removeClass('active'); |
| 699 | + }); |
| 700 | + }, |
| 701 | + switchMediaTrack = function (track) { |
| 702 | + app.currentSession.localStream.getVideoTracks()[0].stop(); |
| 703 | + var stream = app.currentSession.localStream.clone(); |
| 704 | + stream.removeTrack(stream.getVideoTracks()[0]); |
| 705 | + stream.addTrack(track); |
| 706 | + app.currentSession.localStream.getAudioTracks()[0].stop(); |
| 707 | + app.currentSession._replaceTracks(stream); |
| 708 | + app.currentSession.localStream = stream; |
| 709 | + return true; |
| 710 | + }; |
693 | 711 |
|
694 | | - return true; |
| 712 | + if(isActive) { |
| 713 | + stopScreenSharing(); |
| 714 | + } else { |
| 715 | + runScreenSharing(); |
695 | 716 | } |
696 | 717 |
|
697 | | - navigator.mediaDevices[callMethod]({ |
698 | | - video: true, |
699 | | - }).then(stream => { |
700 | | - var videoTrack = stream.getVideoTracks()[0]; |
701 | | - if(callMethod == 'getDisplayMedia') { |
702 | | - videoTrack.onended = function () { |
703 | | - $btn.trigger("click"); |
704 | | - }; |
705 | | - } |
706 | | - $btn.trigger("click", [videoTrack]); |
707 | | - }).catch(function(error) { |
708 | | - console.warn('getMediaDevices', error); |
709 | | - }); |
710 | | - |
711 | 718 | }); |
712 | 719 |
|
713 | 720 | $(document).on('click', '.j-caller__ctrl', function() { |
|
738 | 745 | } else if(QBMediaRecorder.isAvailable()) { |
739 | 746 | if(!isActive){ |
740 | 747 | var connections = app.currentSession.peerConnections, |
741 | | - connection = connections[app.mainVideo], |
742 | | - connectionsCount = Object.keys(connections).length; |
| 748 | + connection = connections[app.mainVideo]; |
743 | 749 |
|
744 | | - if (!connection || connectionsCount !== 1){ |
| 750 | + if (!connection){ |
745 | 751 | return false; |
746 | 752 | } |
747 | 753 |
|
748 | 754 | recorder = new QBMediaRecorder(recorderOpts); |
749 | | - recorder.start(connection.stream); |
| 755 | + |
| 756 | + var elem = document.getElementById("main_video"); |
| 757 | + |
| 758 | + if (typeof elem.srcObject === 'object') { |
| 759 | + recorder.start(elem.srcObject); |
| 760 | + } |
| 761 | + |
750 | 762 | } else { |
751 | 763 | recorder.stop(); |
752 | 764 | } |
|
891 | 903 | console.groupEnd(); |
892 | 904 |
|
893 | 905 | app.currentSession = session; |
894 | | - |
895 | | - ui.insertOccupants().then(function(users) { |
896 | | - app.users = users; |
897 | | - var initiator = _.findWhere(app.users, {id: session.initiatorID}); |
898 | | - app.callees = {}; |
899 | | - /** close previous modal */ |
900 | | - $(ui.income_call).modal('hide'); |
901 | | - |
902 | | - $('.j-ic_initiator').text(initiator.full_name); |
903 | | - |
904 | | - // check the current session state |
905 | | - if (app.currentSession.state !== QB.webrtc.SessionConnectionState.CLOSED){ |
906 | | - $(ui.income_call).modal('show'); |
907 | | - document.getElementById(sounds.rington).play(); |
| 906 | + QB.users.get(Number(session.initiatorID), function(error, user){ |
| 907 | + if (error) { |
| 908 | + console.log(error); |
| 909 | + } else { |
| 910 | + app.users = app.users.filter(function (item) { |
| 911 | + return user.id !== item.id; |
| 912 | + }); |
| 913 | + app.users.push(user); |
| 914 | + /** close previous modal */ |
| 915 | + $(ui.income_call).modal('hide'); |
| 916 | + $('.j-ic_initiator').text(user.full_name); |
| 917 | + // check the current session state |
| 918 | + if (app.currentSession.state !== QB.webrtc.SessionConnectionState.CLOSED){ |
| 919 | + $(ui.income_call).modal('show'); |
| 920 | + document.getElementById(sounds.rington).play(); |
| 921 | + } |
908 | 922 | } |
909 | 923 | }); |
910 | 924 | }; |
911 | 925 |
|
912 | 926 | QB.webrtc.onRejectCallListener = function onRejectCallListener(session, userId, extension) { |
| 927 | + |
| 928 | + if(app.currentSession.ID !== session){ |
| 929 | + return; |
| 930 | + } |
| 931 | + |
913 | 932 | console.group('onRejectCallListener.'); |
914 | 933 | console.log('UserId: ' + userId); |
915 | 934 | console.log('Session: ' + session); |
|
1059 | 1078 |
|
1060 | 1079 | if(app.mainVideo === userId) { |
1061 | 1080 | $('#remote_video_' + userId).removeClass('active'); |
1062 | | - |
1063 | 1081 | app.helpers.changeFilter('#main_video', 'no'); |
1064 | 1082 | app.mainVideo = 0; |
| 1083 | + for(var key in app.currentSession.peerConnections){ |
| 1084 | + if(key != userId |
| 1085 | + && app.currentSession.peerConnections[key].stream !== undefined |
| 1086 | + && app.currentSession.peerConnections[key].stream.active) { |
| 1087 | + app.currentSession.attachMediaStream('main_video', app.currentSession.peerConnections[key].stream); |
| 1088 | + app.mainVideo = key; |
| 1089 | + break; |
| 1090 | + } |
| 1091 | + } |
1065 | 1092 | } |
1066 | 1093 |
|
1067 | 1094 | if( !_.isEmpty(app.currentSession) ) { |
|
1191 | 1218 | } |
1192 | 1219 |
|
1193 | 1220 | function switchMediaTracks() { |
1194 | | - if (!document.getElementById('localVideo').srcObject || !app.currentSession) { |
| 1221 | + |
| 1222 | + var localVideo = document.getElementById('localVideo'); |
| 1223 | + if ( (typeof localVideo == "object" && !localVideo.srcObject) || !app.currentSession) { |
1195 | 1224 | return true; |
1196 | 1225 | } |
1197 | 1226 |
|
|
0 commit comments