From 4f132c418f3903a9b434f0a184703513258e7746 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 15 Jul 2015 17:48:26 +0100 Subject: [PATCH] Fix a couple state bugs. --- src/CallHandler.js | 7 +++- src/controllers/molecules/RoomHeader.js | 52 +++++++++++++++---------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/CallHandler.js b/src/CallHandler.js index ce6d8906af..5fefa7cf10 100644 --- a/src/CallHandler.js +++ b/src/CallHandler.js @@ -19,7 +19,7 @@ limitations under the License. /* * 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' * room_id: @@ -33,6 +33,8 @@ limitations under the License. * { * action: 'place_call', * type: 'voice|video', + * remote_element: DOMVideoElement, // only if type: video + * local_element: DOMVideoElement, // only if type: video * room_id: * } * @@ -48,6 +50,8 @@ limitations under the License. * * { * action: 'answer' + * remote_element: DOMVideoElement, // only if type: video + * local_element: DOMVideoElement, // only if type: video * room_id: * } */ @@ -128,6 +132,7 @@ dis.register(function(payload) { return; // no call to answer } calls[payload.room_id].answer(); + _setCallState(calls[payload.room_id], payload.room_id); break; } }); diff --git a/src/controllers/molecules/RoomHeader.js b/src/controllers/molecules/RoomHeader.js index dde8cf4ef8..b66d1ff90f 100644 --- a/src/controllers/molecules/RoomHeader.js +++ b/src/controllers/molecules/RoomHeader.js @@ -25,29 +25,15 @@ var dis = require("../../dispatcher"); var CallHandler = require("../../CallHandler"); module.exports = { - componentDidMount: function() { - this.dispatcherRef = dis.register(this.onAction); - this.setState({ - 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) { + _setCallState: function(call) { + if (!call) { + this.setState({ + callState: "NO_CALL" + }); return; } - if (payload.action !== 'call_state') { - return; - } - var call = CallHandler.getCall(payload.room_id); var callState = 'NO_CALL'; - if (call && call.state !== 'ended') { + if (call.state !== 'ended') { if (call.state === 'connected') { 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() { dis.dispatch({ action: 'place_call',