Skip to content

Commit 4f132c4

Browse files
committed
Fix a couple state bugs.
1 parent 14a4da5 commit 4f132c4

2 files changed

Lines changed: 38 additions & 21 deletions

File tree

‎src/CallHandler.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
/*
2020
* Manages a list of all the currently active calls.
2121
*
22-
* This handler dispatches when voip calls are added/removed from this list:
22+
* This handler dispatches when voip calls are added/updated/removed from this list:
2323
* {
2424
* action: 'call_state'
2525
* room_id: <room ID of the call>
@@ -33,6 +33,8 @@ limitations under the License.
3333
* {
3434
* action: 'place_call',
3535
* type: 'voice|video',
36+
* remote_element: DOMVideoElement, // only if type: video
37+
* local_element: DOMVideoElement, // only if type: video
3638
* room_id: <room that the place call button was pressed in>
3739
* }
3840
*
@@ -48,6 +50,8 @@ limitations under the License.
4850
*
4951
* {
5052
* action: 'answer'
53+
* remote_element: DOMVideoElement, // only if type: video
54+
* local_element: DOMVideoElement, // only if type: video
5155
* room_id: <room that the answer button was pressed in>
5256
* }
5357
*/
@@ -128,6 +132,7 @@ dis.register(function(payload) {
128132
return; // no call to answer
129133
}
130134
calls[payload.room_id].answer();
135+
_setCallState(calls[payload.room_id], payload.room_id);
131136
break;
132137
}
133138
});

‎src/controllers/molecules/RoomHeader.js‎

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,15 @@ var dis = require("../../dispatcher");
2525
var CallHandler = require("../../CallHandler");
2626

2727
module.exports = {
28-
componentDidMount: function() {
29-
this.dispatcherRef = dis.register(this.onAction);
30-
this.setState({
31-
callState: "NO_CALL"
32-
});
33-
},
34-
35-
componentWillUnmount: function() {
36-
dis.unregister(this.dispatcherRef);
37-
},
38-
39-
onAction: function(payload) {
40-
// if we were given a room_id to track, don't handle anything else.
41-
if (payload.room_id && this.props.room &&
42-
this.props.room.roomId !== payload.room_id) {
43-
return;
44-
}
45-
if (payload.action !== 'call_state') {
28+
_setCallState: function(call) {
29+
if (!call) {
30+
this.setState({
31+
callState: "NO_CALL"
32+
});
4633
return;
4734
}
48-
var call = CallHandler.getCall(payload.room_id);
4935
var callState = 'NO_CALL';
50-
if (call && call.state !== 'ended') {
36+
if (call.state !== 'ended') {
5137
if (call.state === 'connected') {
5238
callState = "IN_CALL";
5339
}
@@ -66,6 +52,32 @@ module.exports = {
6652
});
6753
},
6854

55+
componentDidMount: function() {
56+
this.dispatcherRef = dis.register(this.onAction);
57+
var call;
58+
if (this.props.room) {
59+
call = CallHandler.getCall(this.props.room.roomId);
60+
}
61+
this._setCallState(call);
62+
},
63+
64+
componentWillUnmount: function() {
65+
dis.unregister(this.dispatcherRef);
66+
},
67+
68+
onAction: function(payload) {
69+
// if we were given a room_id to track, don't handle anything else.
70+
if (payload.room_id && this.props.room &&
71+
this.props.room.roomId !== payload.room_id) {
72+
return;
73+
}
74+
if (payload.action !== 'call_state') {
75+
return;
76+
}
77+
var call = CallHandler.getCall(payload.room_id);
78+
this._setCallState(call);
79+
},
80+
6981
onVideoClick: function() {
7082
dis.dispatch({
7183
action: 'place_call',

0 commit comments

Comments
 (0)