0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-15 22:42:23 +01:00

Don't cache isWebRTCSupported because whether webRTC is supported might change part-way through the page's lifecycle if your webrtc support comes from some kind of injected content script (hello OpenWebRTC Sarafi extension)

This commit is contained in:
David Baker 2014-11-06 16:48:01 +00:00
parent e3c3f5a6d0
commit 4b256cab31
4 changed files with 11 additions and 14 deletions

View file

@ -40,14 +40,11 @@ window.RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConne
window.RTCSessionDescription = window.RTCSessionDescription || window.webkitRTCSessionDescription || window.mozRTCSessionDescription; window.RTCSessionDescription = window.RTCSessionDescription || window.webkitRTCSessionDescription || window.mozRTCSessionDescription;
window.RTCIceCandidate = window.RTCIceCandidate || window.webkitRTCIceCandidate || window.mozRTCIceCandidate; window.RTCIceCandidate = window.RTCIceCandidate || window.webkitRTCIceCandidate || window.mozRTCIceCandidate;
// Returns true if the browser supports all required features to make WebRTC call
var isWebRTCSupported = function () {
return !!(navigator.getUserMedia || window.RTCPeerConnection || window.RTCSessionDescription || window.RTCIceCandidate);
};
angular.module('MatrixCall', []) angular.module('MatrixCall', [])
.factory('MatrixCall', ['matrixService', 'matrixPhoneService', 'modelService', '$rootScope', '$timeout', function MatrixCallFactory(matrixService, matrixPhoneService, modelService, $rootScope, $timeout) { .factory('MatrixCall', ['matrixService', 'matrixPhoneService', 'modelService', '$rootScope', '$timeout', function MatrixCallFactory(matrixService, matrixPhoneService, modelService, $rootScope, $timeout) {
$rootScope.isWebRTCSupported = isWebRTCSupported(); $rootScope.isWebRTCSupported = function () {
return !!(navigator.getUserMedia || window.RTCPeerConnection || window.RTCSessionDescription || window.RTCIceCandidate);
};
var MatrixCall = function(room_id) { var MatrixCall = function(room_id) {
this.room_id = room_id; this.room_id = room_id;

View file

@ -60,7 +60,7 @@ angular.module('matrixPhoneService', [])
var MatrixCall = $injector.get('MatrixCall'); var MatrixCall = $injector.get('MatrixCall');
var call = new MatrixCall(event.room_id); var call = new MatrixCall(event.room_id);
if (!isWebRTCSupported()) { if (!$rootScope.isWebRTCSupported()) {
console.log("Incoming call ID "+msg.call_id+" but this browser doesn't support WebRTC"); console.log("Incoming call ID "+msg.call_id+" but this browser doesn't support WebRTC");
// don't hang up the call: there could be other clients connected that do support WebRTC and declining the // don't hang up the call: there could be other clients connected that do support WebRTC and declining the
// the call on their behalf would be really annoying. // the call on their behalf would be really annoying.

View file

@ -85,7 +85,7 @@
</span> </span>
</div> </div>
<span ng-show="currentCall.state == 'ringing'"> <span ng-show="currentCall.state == 'ringing'">
<button ng-click="answerCall()" ng-disabled="!isWebRTCSupported" title="{{isWebRTCSupported ? '' : 'Your browser does not support VoIP' }}">Answer {{ currentCall.type }} call</button> <button ng-click="answerCall()" ng-disabled="!isWebRTCSupported()" title="{{isWebRTCSupported() ? '' : 'Your browser does not support VoIP' }}">Answer {{ currentCall.type }} call</button>
<button ng-click="hangupCall()">Reject</button> <button ng-click="hangupCall()">Reject</button>
</span> </span>
<button ng-click="hangupCall()" ng-show="currentCall && currentCall.state != 'ringing' && currentCall.state != 'ended' && currentCall.state != 'fledgling'">Hang up</button> <button ng-click="hangupCall()" ng-show="currentCall && currentCall.state != 'ringing' && currentCall.state != 'ended' && currentCall.state != 'fledgling'">Hang up</button>

View file

@ -182,8 +182,8 @@
(msg.content.formatted_body | unsanitizedLinky) : (msg.content.formatted_body | unsanitizedLinky) :
(msg.content.msgtype === 'm.text' && msg.type === 'm.room.message') ? (msg.content.body | linky:'_blank') : '' "/> (msg.content.msgtype === 'm.text' && msg.type === 'm.room.message') ? (msg.content.body | linky:'_blank') : '' "/>
<span ng-show='msg.type === "m.call.invite" && msg.user_id == state.user_id'>Outgoing Call{{ isWebRTCSupported ? '' : ' (But your browser does not support VoIP)' }}</span> <span ng-show='msg.type === "m.call.invite" && msg.user_id == state.user_id'>Outgoing Call{{ isWebRTCSupported() ? '' : ' (But your browser does not support VoIP)' }}</span>
<span ng-show='msg.type === "m.call.invite" && msg.user_id != state.user_id'>Incoming Call{{ isWebRTCSupported ? '' : ' (But your browser does not support VoIP)' }}</span> <span ng-show='msg.type === "m.call.invite" && msg.user_id != state.user_id'>Incoming Call{{ isWebRTCSupported() ? '' : ' (But your browser does not support VoIP)' }}</span>
<div ng-show='msg.content.msgtype === "m.image"'> <div ng-show='msg.content.msgtype === "m.image"'>
<div ng-hide='msg.content.thumbnail_url' ng-style="msg.content.body.h && { 'height' : (msg.content.body.h < 320) ? msg.content.body.h : 320}"> <div ng-hide='msg.content.thumbnail_url' ng-style="msg.content.body.h && { 'height' : (msg.content.body.h < 320) ? msg.content.body.h : 320}">
@ -248,15 +248,15 @@
<button ng-click="leaveRoom()" ng-disabled="state.permission_denied">Leave</button> <button ng-click="leaveRoom()" ng-disabled="state.permission_denied">Leave</button>
<button ng-click="startVoiceCall()" <button ng-click="startVoiceCall()"
ng-show="(currentCall == undefined || currentCall.state == 'ended')" ng-show="(currentCall == undefined || currentCall.state == 'ended')"
ng-disabled="state.permission_denied || !isWebRTCSupported || memberCount() != 2" ng-disabled="state.permission_denied || !isWebRTCSupported() || memberCount() != 2"
title ="{{ !isWebRTCSupported ? 'VoIP requires webRTC but your browser does not support it' : (memberCount() == 2 ? '' : 'VoIP calls can only be made in rooms with two participants') }}" title ="{{ !isWebRTCSupported() ? 'VoIP requires webRTC but your browser does not support it' : (memberCount() == 2 ? '' : 'VoIP calls can only be made in rooms with two participants') }}"
> >
Voice Call Voice Call
</button> </button>
<button ng-click="startVideoCall()" <button ng-click="startVideoCall()"
ng-show="(currentCall == undefined || currentCall.state == 'ended')" ng-show="(currentCall == undefined || currentCall.state == 'ended')"
ng-disabled="state.permission_denied || !isWebRTCSupported || memberCount() != 2" ng-disabled="state.permission_denied || !isWebRTCSupported() || memberCount() != 2"
title ="{{ !isWebRTCSupported ? 'VoIP requires webRTC but your browser does not support it' : (memberCount() == 2 ? '' : 'VoIP calls can only be made in rooms with two participants') }}" title ="{{ !isWebRTCSupported() ? 'VoIP requires webRTC but your browser does not support it' : (memberCount() == 2 ? '' : 'VoIP calls can only be made in rooms with two participants') }}"
> >
Video Call Video Call
</button> </button>