From 30abf81ed4ebef61816a6364c683fa0a127e4bba Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 29 Feb 2016 13:43:22 +0000 Subject: [PATCH] Fix CallView in left panel Make CallView cope with not being passed a room. Fixes https://github.com/vector-im/vector-web/issues/1049, introduced in 7a20fda7, which made vector crash when you switched to another room with an active call. --- src/components/views/voip/CallView.js | 34 +++++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/components/views/voip/CallView.js b/src/components/views/voip/CallView.js index 13abcb7f9d..f4b85f83bf 100644 --- a/src/components/views/voip/CallView.js +++ b/src/components/views/voip/CallView.js @@ -23,8 +23,9 @@ module.exports = React.createClass({ displayName: 'CallView', propTypes: { - // js-sdk room object - room: React.PropTypes.object.isRequired, + // js-sdk room object. If set, we will only show calls for the given + // room; if not, we will show any active call. + room: React.PropTypes.object, // A Conference Handler implementation // Must have a function signature: @@ -44,7 +45,7 @@ module.exports = React.createClass({ componentDidMount: function() { this.dispatcherRef = dis.register(this.onAction); - this.showCall(this.props.room.roomId); + this.showCall(); }, componentWillUnmount: function() { @@ -54,20 +55,27 @@ module.exports = React.createClass({ onAction: function(payload) { // don't filter out payloads for room IDs other than props.room because // we may be interested in the conf 1:1 room - if (payload.action !== 'call_state' || !payload.room_id) { + if (payload.action !== 'call_state') { return; } - this.showCall(payload.room_id); + this.showCall(); }, - showCall: function(roomId) { - var call = ( - CallHandler.getCallForRoom(roomId) || - (this.props.ConferenceHandler ? - this.props.ConferenceHandler.getConferenceCallForRoom(roomId) : - null - ) - ); + showCall: function() { + var call; + + if (this.props.room) { + var roomId = this.props.room.roomId; + call = CallHandler.getCallForRoom(roomId) || + (this.props.ConferenceHandler ? + this.props.ConferenceHandler.getConferenceCallForRoom(roomId) : + null + ); + } + else { + call = CallHandler.getAnyActiveCall(); + } + if (call) { call.setLocalVideoElement(this.getVideoView().getLocalVideoElement()); call.setRemoteVideoElement(this.getVideoView().getRemoteVideoElement());