diff --git a/resources/html/webrtcgateway/test/components/app.jsx b/resources/html/webrtcgateway/test/components/app.jsx index 7e1a059..8609e0d 100644 --- a/resources/html/webrtcgateway/test/components/app.jsx +++ b/resources/html/webrtcgateway/test/components/app.jsx @@ -1,162 +1,167 @@ var SylkTest = React.createClass({ getInitialState: function() { return { connection: null, connectionState: null, account: null, registrationState: null, currentCall: null, callState: null, }; }, getServerUrl: function() { return window.location.protocol.replace('http', 'ws') + '//' + window.location.host + '/webrtcgateway/ws'; }, connectionStateChanged: function(oldState, newState) { switch (newState) { case 'closed': this.setState({connection: null, connectionState: newState}); break; case 'disconnected': if (this.state.currentCall) { this.state.currentCall.terminate(); } this.setState({account: null, registrationState: null, currentCall: null, callState: null, connectionState: newState}); break; default: this.setState({connectionState: newState}); break; } }, registrationStateChanged: function(oldState, newState, data) { var state = newState; if (newState === 'failed') { state += ' (' + data.reason + ')' } this.setState({registrationState: state}); }, callStateChanged: function(oldState, newState, data) { var state = newState; var currentCall = this.state.currentCall; if (newState === 'terminated') { state += ' (' + data.reason + ')'; currentCall = null; setTimeout(() => { if (this.state.currentCall === null) { this.setState({callState: null}); } }, 4000); } this.setState({currentCall: currentCall, callState: state}); }, setAccount: function(account) { if (account !== null) { account.on('registrationStateChanged', this.registrationStateChanged); account.on('incomingCall', this.handleNewCall); account.on('outgoingCall', this.handleNewCall); } this.setState({account: account}); }, handleNewCall: function(call) { if (this.state.currentCall !== null) { call.terminate(); } else { call.on('stateChanged', this.callStateChanged); this.setState({currentCall: call, callState: call.state}); } }, toggleConnect: function(event) { event.preventDefault(); if (this.state.connection === null) { var connection = sylkrtc.createConnection({server: this.getServerUrl()}); connection.on('stateChanged', this.connectionStateChanged); this.setState({connection: connection}); } else { this.state.connection.close(); } }, render: function() { var accountBox; var callBox; var videoBox; + var ringtonePlayer; if (sylkrtc.isWebRTCSupported()) { accountBox = ; if (this.state.callState === 'established') { videoBox = } else { + if (this.state.currentCall) { + ringtonePlayer = + } if (this.state.currentCall === null || this.state.currentCall.direction === 'outgoing') { callBox = } else { callBox = } } } else { accountBox =

Your browser does not support WebRTC

Too bad! Checkout the WebRTC support across browsers in the link below.
Is WebRTC ready yet?

; } return (

{accountBox}
{videoBox} {callBox} + {ringtonePlayer}

WebSocket server — {this.getServerUrl()}
); } }); diff --git a/resources/html/webrtcgateway/test/components/ringtoneplayer.jsx b/resources/html/webrtcgateway/test/components/ringtoneplayer.jsx new file mode 100644 index 0000000..e12a225 --- /dev/null +++ b/resources/html/webrtcgateway/test/components/ringtoneplayer.jsx @@ -0,0 +1,30 @@ + +var RingtonePlayer = React.createClass({ + audioEnded: function() { + this.timeout = setTimeout(() => { + this.refs.audio.getDOMNode().play(); + }, 4500); + }, + + componentDidMount: function() { + this.refs.audio.getDOMNode().addEventListener('ended', this.audioEnded); + }, + + componentWillUnmount: function() { + if (this.timeout) { + clearTimeout(this.timeout); + } + this.timeout = null; + this.refs.audio.getDOMNode().removeEventListener('ended', this.audioEnded); + }, + + render: function() { + return ( +
+ +
+ ); + } +}); diff --git a/resources/html/webrtcgateway/test/index.html b/resources/html/webrtcgateway/test/index.html index 12d7994..5d5243f 100644 --- a/resources/html/webrtcgateway/test/index.html +++ b/resources/html/webrtcgateway/test/index.html @@ -1,21 +1,22 @@ SylkServer WebRTC Test Application + diff --git a/resources/html/webrtcgateway/test/sounds/ringtone.wav b/resources/html/webrtcgateway/test/sounds/ringtone.wav new file mode 100644 index 0000000..e72dd50 Binary files /dev/null and b/resources/html/webrtcgateway/test/sounds/ringtone.wav differ