From 78bea916e11dc9116cbc03070a7c75a54ba8bb91 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 15 Jul 2015 14:06:44 +0100 Subject: [PATCH] Dispatch events when calls are made/received. --- skins/base/views/molecules/VideoView.js | 5 ++-- skins/base/views/organisms/RoomView.js | 6 +--- src/controllers/molecules/RoomHeader.js | 14 +++++++-- src/controllers/molecules/VideoView.js | 38 +++++++++++++++++++++++++ src/controllers/pages/MatrixChat.js | 6 ++++ 5 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 src/controllers/molecules/VideoView.js diff --git a/skins/base/views/molecules/VideoView.js b/skins/base/views/molecules/VideoView.js index 813740fb10..be594142ce 100644 --- a/skins/base/views/molecules/VideoView.js +++ b/skins/base/views/molecules/VideoView.js @@ -20,11 +20,12 @@ var React = require('react'); var MatrixClientPeg = require("../../../../src/MatrixClientPeg"); var ComponentBroker = require('../../../../src/ComponentBroker'); - +var VideoViewController = require("../../../../src/controllers/molecules/VideoView"); var VideoFeed = ComponentBroker.get('atoms/VideoFeed'); module.exports = React.createClass({ displayName: 'VideoView', + mixins: [VideoViewController], getRemoteVideoElement: function() { return this.refs.remote.getDOMNode(); @@ -45,5 +46,5 @@ module.exports = React.createClass({ ); - }, + } }); \ No newline at end of file diff --git a/skins/base/views/organisms/RoomView.js b/skins/base/views/organisms/RoomView.js index 26b96baaee..c7eb1474ce 100644 --- a/skins/base/views/organisms/RoomView.js +++ b/skins/base/views/organisms/RoomView.js @@ -37,10 +37,6 @@ module.exports = React.createClass({ displayName: 'RoomView', mixins: [RoomViewController], - getVideoView: function() { - return this.refs.video; - }, - render: function() { var myUserId = MatrixClientPeg.get().credentials.userId; if (this.state.room.currentState.members[myUserId].membership == 'invite') { @@ -73,7 +69,7 @@ module.exports = React.createClass({
- +
diff --git a/src/controllers/molecules/RoomHeader.js b/src/controllers/molecules/RoomHeader.js index 49f85caa9b..047c378997 100644 --- a/src/controllers/molecules/RoomHeader.js +++ b/src/controllers/molecules/RoomHeader.js @@ -16,14 +16,22 @@ limitations under the License. 'use strict'; -var MatrixClientPeg = require("../../MatrixClientPeg"); +var dis = require("../../dispatcher"); module.exports = { onVideoClick: function() { - console.log("video clicked"); + dis.dispatch({ + action: 'place_call', + type: "video", + room_id: this.props.room.roomId + }); }, onVoiceClick: function() { - console.log("voice clicked"); + dis.dispatch({ + action: 'place_call', + type: "voice", + room_id: this.props.room.roomId + }); } }; diff --git a/src/controllers/molecules/VideoView.js b/src/controllers/molecules/VideoView.js new file mode 100644 index 0000000000..245f8bb9d6 --- /dev/null +++ b/src/controllers/molecules/VideoView.js @@ -0,0 +1,38 @@ +/* +Copyright 2015 OpenMarket Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +'use strict'; + +var dis = require("../../dispatcher"); + +module.exports = { + + componentDidMount: function() { + this.dispatcherRef = dis.register(this.onAction); + }, + + onAction: function(payload) { + switch(payload.action) { + case 'place_call': + console.log("Place %s call in %s", payload.type, payload.room_id); + break; + case 'incoming_call': + console.log("Incoming call: %s", payload.call); + break; + } + } +}; + diff --git a/src/controllers/pages/MatrixChat.js b/src/controllers/pages/MatrixChat.js index 717f91e7a4..95776c2a23 100644 --- a/src/controllers/pages/MatrixChat.js +++ b/src/controllers/pages/MatrixChat.js @@ -116,6 +116,12 @@ module.exports = { that.setState({ready: true, currentRoom: firstRoom}); dis.dispatch({action: 'focus_composer'}); }); + cli.on('Call.incoming', function(call) { + dis.dispatch({ + action: 'incoming_call', + call: call + }); + }); Notifier.start(); cli.startClient(); },