Change call signalling messages to be their own types of room events rather than room messages with different msgtypes: room messages should be things that the client can display as a unit message to the user.

This commit is contained in:
David Baker 2014-08-29 13:23:01 +01:00
parent 171d8b032f
commit 5308e3026a
5 changed files with 27 additions and 18 deletions

View File

@ -31,6 +31,7 @@ angular.module('eventHandlerService', [])
var MSG_EVENT = "MSG_EVENT"; var MSG_EVENT = "MSG_EVENT";
var MEMBER_EVENT = "MEMBER_EVENT"; var MEMBER_EVENT = "MEMBER_EVENT";
var PRESENCE_EVENT = "PRESENCE_EVENT"; var PRESENCE_EVENT = "PRESENCE_EVENT";
var CALL_EVENT = "CALL_EVENT";
var InitialSyncDeferred = $q.defer(); var InitialSyncDeferred = $q.defer();
@ -94,11 +95,16 @@ angular.module('eventHandlerService', [])
$rootScope.presence[event.content.user_id] = event; $rootScope.presence[event.content.user_id] = event;
$rootScope.$broadcast(PRESENCE_EVENT, event, isLiveEvent); $rootScope.$broadcast(PRESENCE_EVENT, event, isLiveEvent);
}; };
var handleCallEvent = function(event, isLiveEvent) {
$rootScope.$broadcast(CALL_EVENT, event, isLiveEvent);
};
return { return {
MSG_EVENT: MSG_EVENT, MSG_EVENT: MSG_EVENT,
MEMBER_EVENT: MEMBER_EVENT, MEMBER_EVENT: MEMBER_EVENT,
PRESENCE_EVENT: PRESENCE_EVENT, PRESENCE_EVENT: PRESENCE_EVENT,
CALL_EVENT: CALL_EVENT,
handleEvent: function(event, isLiveEvent) { handleEvent: function(event, isLiveEvent) {
@ -116,6 +122,9 @@ angular.module('eventHandlerService', [])
console.log("Unable to handle event type " + event.type); console.log("Unable to handle event type " + event.type);
break; break;
} }
if (event.type.indexOf('m.call.') == 0) {
handleCallEvent(event, isLiveEvent);
}
}, },
// isLiveEvents determines whether notifications should be shown, whether // isLiveEvents determines whether notifications should be shown, whether

View File

@ -84,11 +84,10 @@ angular.module('MatrixCall', [])
}); });
var content = { var content = {
msgtype: "m.call.hangup",
version: 0, version: 0,
call_id: this.call_id, call_id: this.call_id,
}; };
matrixService.sendMessage(this.room_id, undefined, content).then(this.messageSent, this.messageSendFailed); matrixService.sendEvent(this.room_id, 'm.call.hangup', undefined, content).then(this.messageSent, this.messageSendFailed);
this.state = 'ended'; this.state = 'ended';
}; };
@ -135,12 +134,11 @@ angular.module('MatrixCall', [])
console.trace(event); console.trace(event);
if (event.candidate) { if (event.candidate) {
var content = { var content = {
msgtype: "m.call.candidate",
version: 0, version: 0,
call_id: this.call_id, call_id: this.call_id,
candidate: event.candidate candidate: event.candidate
}; };
matrixService.sendMessage(this.room_id, undefined, content).then(this.messageSent, this.messageSendFailed); matrixService.sendEvent(this.room_id, 'm.call.candidate', undefined, content).then(this.messageSent, this.messageSendFailed);
} }
} }
@ -163,12 +161,11 @@ angular.module('MatrixCall', [])
this.peerConn.setLocalDescription(description); this.peerConn.setLocalDescription(description);
var content = { var content = {
msgtype: "m.call.invite",
version: 0, version: 0,
call_id: this.call_id, call_id: this.call_id,
offer: description offer: description
}; };
matrixService.sendMessage(this.room_id, undefined, content).then(this.messageSent, this.messageSendFailed); matrixService.sendEvent(this.room_id, 'm.call.invite', undefined, content).then(this.messageSent, this.messageSendFailed);
this.state = 'invite_sent'; this.state = 'invite_sent';
}; };
@ -176,12 +173,11 @@ angular.module('MatrixCall', [])
console.trace("Created answer: "+description); console.trace("Created answer: "+description);
this.peerConn.setLocalDescription(description); this.peerConn.setLocalDescription(description);
var content = { var content = {
msgtype: "m.call.answer",
version: 0, version: 0,
call_id: this.call_id, call_id: this.call_id,
answer: description answer: description
}; };
matrixService.sendMessage(this.room_id, undefined, content).then(this.messageSent, this.messageSendFailed); matrixService.sendEvent(this.room_id, 'm.call.answer', undefined, content).then(this.messageSent, this.messageSendFailed);
this.state = 'connecting'; this.state = 'connecting';
}; };

View File

@ -21,39 +21,39 @@ angular.module('matrixPhoneService', [])
var matrixPhoneService = function() { var matrixPhoneService = function() {
}; };
matrixPhoneService.CALL_EVENT = "CALL_EVENT"; matrixPhoneService.INCOMING_CALL_EVENT = "INCOMING_CALL_EVENT";
matrixPhoneService.allCalls = {}; matrixPhoneService.allCalls = {};
matrixPhoneService.callPlaced = function(call) { matrixPhoneService.callPlaced = function(call) {
matrixPhoneService.allCalls[call.call_id] = call; matrixPhoneService.allCalls[call.call_id] = call;
}; };
$rootScope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { $rootScope.$on(eventHandlerService.CALL_EVENT, function(ngEvent, event, isLive) {
if (!isLive) return; // until matrix supports expiring messages if (!isLive) return; // until matrix supports expiring messages
if (event.user_id == matrixService.config().user_id) return; if (event.user_id == matrixService.config().user_id) return;
var msg = event.content; var msg = event.content;
if (msg.msgtype == 'm.call.invite') { if (event.type == 'm.call.invite') {
var MatrixCall = $injector.get('MatrixCall'); var MatrixCall = $injector.get('MatrixCall');
var call = new MatrixCall(event.room_id); var call = new MatrixCall(event.room_id);
call.call_id = msg.call_id; call.call_id = msg.call_id;
call.initWithInvite(msg); call.initWithInvite(msg);
matrixPhoneService.allCalls[call.call_id] = call; matrixPhoneService.allCalls[call.call_id] = call;
$rootScope.$broadcast(matrixPhoneService.CALL_EVENT, call); $rootScope.$broadcast(matrixPhoneService.INCOMING_CALL_EVENT, call);
} else if (msg.msgtype == 'm.call.answer') { } else if (event.type == 'm.call.answer') {
var call = matrixPhoneService.allCalls[msg.call_id]; var call = matrixPhoneService.allCalls[msg.call_id];
if (!call) { if (!call) {
console.trace("Got answer for unknown call ID "+msg.call_id); console.trace("Got answer for unknown call ID "+msg.call_id);
return; return;
} }
call.receivedAnswer(msg); call.receivedAnswer(msg);
} else if (msg.msgtype == 'm.call.candidate') { } else if (event.type == 'm.call.candidate') {
var call = matrixPhoneService.allCalls[msg.call_id]; var call = matrixPhoneService.allCalls[msg.call_id];
if (!call) { if (!call) {
console.trace("Got candidate for unknown call ID "+msg.call_id); console.trace("Got candidate for unknown call ID "+msg.call_id);
return; return;
} }
call.gotRemoteIceCandidate(msg.candidate); call.gotRemoteIceCandidate(msg.candidate);
} else if (msg.msgtype == 'm.call.hangup') { } else if (event.type == 'm.call.hangup') {
var call = matrixPhoneService.allCalls[msg.call_id]; var call = matrixPhoneService.allCalls[msg.call_id];
if (!call) { if (!call) {
console.trace("Got hangup for unknown call ID "+msg.call_id); console.trace("Got hangup for unknown call ID "+msg.call_id);

View File

@ -172,9 +172,9 @@ angular.module('matrixService', [])
return doRequest("GET", path, undefined, {}); return doRequest("GET", path, undefined, {});
}, },
sendMessage: function(room_id, txn_id, content) { sendEvent: function(room_id, eventType, txn_id, content) {
// The REST path spec // The REST path spec
var path = "/rooms/$room_id/send/m.room.message/$txn_id"; var path = "/rooms/$room_id/send/"+eventType+"/$txn_id";
if (!txn_id) { if (!txn_id) {
txn_id = "m" + new Date().getTime(); txn_id = "m" + new Date().getTime();
@ -190,6 +190,10 @@ angular.module('matrixService', [])
return doRequest("PUT", path, undefined, content); return doRequest("PUT", path, undefined, content);
}, },
sendMessage: function(room_id, txn_id, content) {
return self.sendObject(room_id, 'm.room.message', txn_id, content);
},
// Send a text message // Send a text message
sendTextMessage: function(room_id, body, msg_id) { sendTextMessage: function(room_id, body, msg_id) {
var content = { var content = {

View File

@ -83,7 +83,7 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput'])
updatePresence(event); updatePresence(event);
}); });
$rootScope.$on(matrixPhoneService.CALL_EVENT, function(ngEvent, call) { $rootScope.$on(matrixPhoneService.INCOMING_CALL_EVENT, function(ngEvent, call) {
console.trace("incoming call"); console.trace("incoming call");
call.onError = $scope.onCallError; call.onError = $scope.onCallError;
call.onHangup = $scope.onCallHangup; call.onHangup = $scope.onCallHangup;