|
184 | 184 | this.currentRoomToken = token; |
185 | 185 | this._trigger('joinRoom', [token]); |
186 | 186 | this._runPendingChatRequests(); |
| 187 | + if (this.currentCallToken === token) { |
| 188 | + // We were in this call before, join again. |
| 189 | + this.joinCall(token); |
| 190 | + } else { |
| 191 | + this.currentCallToken = null; |
| 192 | + } |
187 | 193 | this._joinRoomSuccess(token, result.ocs.data.sessionId); |
188 | 194 | }.bind(this), |
189 | 195 | error: function (result) { |
|
270 | 276 | // Override in subclasses if necessary. |
271 | 277 | }; |
272 | 278 |
|
273 | | - OCA.Talk.Signaling.Base.prototype.leaveCall = function(token) { |
| 279 | + OCA.Talk.Signaling.Base.prototype.leaveCall = function(token, keepToken) { |
274 | 280 |
|
275 | 281 | if (!token) { |
276 | 282 | return; |
|
284 | 290 | this._trigger('leaveCall', [token]); |
285 | 291 | this._leaveCallSuccess(token); |
286 | 292 | // We left the current call. |
287 | | - if (token === this.currentCallToken) { |
| 293 | + if (!keepToken && token === this.currentCallToken) { |
288 | 294 | this.currentCallToken = null; |
289 | 295 | } |
290 | 296 | }.bind(this) |
|
455 | 461 | } |
456 | 462 | }; |
457 | 463 |
|
| 464 | + OCA.Talk.Signaling.Internal.prototype.forceReconnect = function(/* newSession */) { |
| 465 | + console.error("Forced reconnects are not supported with the internal signaling."); |
| 466 | + }; |
| 467 | + |
458 | 468 | OCA.Talk.Signaling.Internal.prototype._sendMessageWithCallback = function(ev) { |
459 | 469 | var message = [{ |
460 | 470 | ev: ev |
|
719 | 729 | this.id = 1; |
720 | 730 | this.pendingMessages = []; |
721 | 731 | this.connected = false; |
| 732 | + this._forceReconnect = false; |
722 | 733 | this.socket = new WebSocket(this.url); |
723 | 734 | window.signalingSocket = this.socket; |
724 | 735 | this.socket.onopen = function(event) { |
|
779 | 790 | }.bind(this); |
780 | 791 | }; |
781 | 792 |
|
782 | | - OCA.Talk.Signaling.Standalone.prototype.disconnect = function() { |
783 | | - if (this.socket) { |
| 793 | + OCA.Talk.Signaling.Standalone.prototype.sendBye = function() { |
| 794 | + if (this.connected) { |
784 | 795 | this.doSend({ |
785 | 796 | "type": "bye", |
786 | 797 | "bye": {} |
787 | 798 | }); |
| 799 | + } |
| 800 | + this.resumeId = null; |
| 801 | + }; |
| 802 | + |
| 803 | + OCA.Talk.Signaling.Standalone.prototype.disconnect = function() { |
| 804 | + this.sendBye(); |
| 805 | + if (this.socket) { |
788 | 806 | this.socket.close(); |
789 | 807 | this.socket = null; |
790 | 808 | } |
791 | 809 | OCA.Talk.Signaling.Base.prototype.disconnect.apply(this, arguments); |
792 | 810 | }; |
793 | 811 |
|
| 812 | + OCA.Talk.Signaling.Standalone.prototype.forceReconnect = function(newSession) { |
| 813 | + if (!this.connected) { |
| 814 | + if (!newSession) { |
| 815 | + // Not connected, will do reconnect anyway. |
| 816 | + return; |
| 817 | + } |
| 818 | + |
| 819 | + this._forceReconnect = true; |
| 820 | + return; |
| 821 | + } |
| 822 | + |
| 823 | + this._forceReconnect = false; |
| 824 | + if (newSession) { |
| 825 | + if (this.currentCallToken) { |
| 826 | + // Mark this session as "no longer in the call". |
| 827 | + this.leaveCall(this.currentCallToken, true); |
| 828 | + } |
| 829 | + this.sendBye(); |
| 830 | + } |
| 831 | + if (this.socket) { |
| 832 | + // Trigger reconnect. |
| 833 | + this.socket.close(); |
| 834 | + } |
| 835 | + }; |
| 836 | + |
794 | 837 | OCA.Talk.Signaling.Standalone.prototype.sendCallMessage = function(data) { |
795 | 838 | this.doSend({ |
796 | 839 | "type": "message", |
|
804 | 847 | }); |
805 | 848 | }; |
806 | 849 |
|
| 850 | + OCA.Talk.Signaling.Standalone.prototype.sendRoomMessage = function(data) { |
| 851 | + if (!this.currentCallToken) { |
| 852 | + console.warn("Not in a room, not sending room message", data); |
| 853 | + return; |
| 854 | + } |
| 855 | + |
| 856 | + this.doSend({ |
| 857 | + "type": "message", |
| 858 | + "message": { |
| 859 | + "recipient": { |
| 860 | + "type": "room" |
| 861 | + }, |
| 862 | + "data": data |
| 863 | + } |
| 864 | + }); |
| 865 | + }; |
| 866 | + |
807 | 867 | OCA.Talk.Signaling.Standalone.prototype.doSend = function(msg, callback) { |
808 | 868 | if (!this.connected && msg.type !== "hello") { |
809 | 869 | // Defer sending any messages until the hello rsponse has been |
|
833 | 893 | } |
834 | 894 | }; |
835 | 895 | } else { |
| 896 | + // Already reconnected with a new session. |
| 897 | + this._forceReconnect = false; |
836 | 898 | var user = OC.getCurrentUser(); |
837 | 899 | var url = OC.linkToOCS('apps/spreed/api/v1/signaling', 2) + 'backend'; |
838 | 900 | msg = { |
|
870 | 932 |
|
871 | 933 | var resumedSession = !!this.resumeId; |
872 | 934 | this.connected = true; |
| 935 | + if (this._forceReconnect && resumedSession) { |
| 936 | + console.log("Perform pending forced reconnect"); |
| 937 | + this.forceReconnect(true); |
| 938 | + return; |
| 939 | + } |
873 | 940 | this.sessionId = data.hello.sessionid; |
874 | 941 | this.resumeId = data.hello.resumeid; |
875 | 942 | this.features = {}; |
|
921 | 988 | }; |
922 | 989 |
|
923 | 990 | OCA.Talk.Signaling.Standalone.prototype._joinRoomSuccess = function(token, nextcloudSessionId) { |
| 991 | + if (!this.sessionId) { |
| 992 | + console.log("No hello response received yet, not joining room", token); |
| 993 | + return; |
| 994 | + } |
| 995 | + |
924 | 996 | console.log("Join room", token); |
925 | 997 | this.doSend({ |
926 | 998 | "type": "room", |
|
1110 | 1182 | OCA.Talk.Signaling.Standalone.prototype.processRoomParticipantsEvent = function(data) { |
1111 | 1183 | switch (data.event.type) { |
1112 | 1184 | case "update": |
1113 | | - this._trigger("usersChanged", [data.event.update.users]); |
| 1185 | + this._trigger("usersChanged", [data.event.update.users || []]); |
1114 | 1186 | this._trigger("participantListChanged"); |
1115 | 1187 | this.internalSyncRooms(); |
1116 | 1188 | break; |
|
1140 | 1212 | this.receiveMessagesAgain = false; |
1141 | 1213 | }; |
1142 | 1214 |
|
| 1215 | + OCA.Talk.Signaling.Standalone.prototype.requestOffer = function(sessionid, roomType) { |
| 1216 | + if (!this.hasFeature("mcu")) { |
| 1217 | + console.warn("Can't request an offer without a MCU."); |
| 1218 | + return; |
| 1219 | + } |
| 1220 | + |
| 1221 | + if (typeof(sessionid) !== "string") { |
| 1222 | + // Got a user object. |
| 1223 | + sessionid = sessionid.sessionId || sessionid.sessionid; |
| 1224 | + } |
| 1225 | + console.log("Request offer from", sessionid); |
| 1226 | + this.doSend({ |
| 1227 | + "type": "message", |
| 1228 | + "message": { |
| 1229 | + "recipient": { |
| 1230 | + "type": "session", |
| 1231 | + "sessionid": sessionid |
| 1232 | + }, |
| 1233 | + "data": { |
| 1234 | + "type": "requestoffer", |
| 1235 | + "roomType": roomType |
| 1236 | + } |
| 1237 | + } |
| 1238 | + }); |
| 1239 | + }; |
| 1240 | + |
| 1241 | + OCA.Talk.Signaling.Standalone.prototype.sendOffer = function(sessionid, roomType) { |
| 1242 | + // TODO(jojo): This should go away and "requestOffer" should be used |
| 1243 | + // instead by peers that want an offer by the MCU. See the calling |
| 1244 | + // location for further details. |
| 1245 | + if (!this.hasFeature("mcu")) { |
| 1246 | + console.warn("Can't send an offer without a MCU."); |
| 1247 | + return; |
| 1248 | + } |
| 1249 | + |
| 1250 | + if (typeof(sessionid) !== "string") { |
| 1251 | + // Got a user object. |
| 1252 | + sessionid = sessionid.sessionId || sessionid.sessionid; |
| 1253 | + } |
| 1254 | + console.log("Send offer to", sessionid); |
| 1255 | + this.doSend({ |
| 1256 | + "type": "message", |
| 1257 | + "message": { |
| 1258 | + "recipient": { |
| 1259 | + "type": "session", |
| 1260 | + "sessionid": sessionid |
| 1261 | + }, |
| 1262 | + "data": { |
| 1263 | + "type": "sendoffer", |
| 1264 | + "roomType": roomType |
| 1265 | + } |
| 1266 | + } |
| 1267 | + }); |
| 1268 | + }; |
| 1269 | + |
1143 | 1270 | })(OCA, OC, $); |
0 commit comments