Fix a couple state bugs.

pull/1/head
Kegan Dougal 2015-07-15 17:48:26 +01:00
parent 14a4da54f8
commit 4f132c418f
2 changed files with 38 additions and 21 deletions

View File

@ -19,7 +19,7 @@ limitations under the License.
/* /*
* Manages a list of all the currently active calls. * Manages a list of all the currently active calls.
* *
* This handler dispatches when voip calls are added/removed from this list: * This handler dispatches when voip calls are added/updated/removed from this list:
* { * {
* action: 'call_state' * action: 'call_state'
* room_id: <room ID of the call> * room_id: <room ID of the call>
@ -33,6 +33,8 @@ limitations under the License.
* { * {
* action: 'place_call', * action: 'place_call',
* type: 'voice|video', * type: 'voice|video',
* remote_element: DOMVideoElement, // only if type: video
* local_element: DOMVideoElement, // only if type: video
* room_id: <room that the place call button was pressed in> * room_id: <room that the place call button was pressed in>
* } * }
* *
@ -48,6 +50,8 @@ limitations under the License.
* *
* { * {
* action: 'answer' * action: 'answer'
* remote_element: DOMVideoElement, // only if type: video
* local_element: DOMVideoElement, // only if type: video
* room_id: <room that the answer button was pressed in> * room_id: <room that the answer button was pressed in>
* } * }
*/ */
@ -128,6 +132,7 @@ dis.register(function(payload) {
return; // no call to answer return; // no call to answer
} }
calls[payload.room_id].answer(); calls[payload.room_id].answer();
_setCallState(calls[payload.room_id], payload.room_id);
break; break;
} }
}); });

View File

@ -25,29 +25,15 @@ var dis = require("../../dispatcher");
var CallHandler = require("../../CallHandler"); var CallHandler = require("../../CallHandler");
module.exports = { module.exports = {
componentDidMount: function() { _setCallState: function(call) {
this.dispatcherRef = dis.register(this.onAction); if (!call) {
this.setState({ this.setState({
callState: "NO_CALL" callState: "NO_CALL"
}); });
},
componentWillUnmount: function() {
dis.unregister(this.dispatcherRef);
},
onAction: function(payload) {
// if we were given a room_id to track, don't handle anything else.
if (payload.room_id && this.props.room &&
this.props.room.roomId !== payload.room_id) {
return; return;
} }
if (payload.action !== 'call_state') {
return;
}
var call = CallHandler.getCall(payload.room_id);
var callState = 'NO_CALL'; var callState = 'NO_CALL';
if (call && call.state !== 'ended') { if (call.state !== 'ended') {
if (call.state === 'connected') { if (call.state === 'connected') {
callState = "IN_CALL"; callState = "IN_CALL";
} }
@ -66,6 +52,32 @@ module.exports = {
}); });
}, },
componentDidMount: function() {
this.dispatcherRef = dis.register(this.onAction);
var call;
if (this.props.room) {
call = CallHandler.getCall(this.props.room.roomId);
}
this._setCallState(call);
},
componentWillUnmount: function() {
dis.unregister(this.dispatcherRef);
},
onAction: function(payload) {
// if we were given a room_id to track, don't handle anything else.
if (payload.room_id && this.props.room &&
this.props.room.roomId !== payload.room_id) {
return;
}
if (payload.action !== 'call_state') {
return;
}
var call = CallHandler.getCall(payload.room_id);
this._setCallState(call);
},
onVideoClick: function() { onVideoClick: function() {
dis.dispatch({ dis.dispatch({
action: 'place_call', action: 'place_call',