From 10680ace1731a64af1c27cda345362ebf96ff304 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 17 Nov 2017 14:51:37 +0000 Subject: [PATCH 1/5] Fix the force TURN option Option needed to be passed in when creating a webrtc call, but for incoming calls the js-sdk creates the call itself, so the app never gets a chance to set the option. --- src/client.js | 15 ++++++++++++++- src/webrtc/call.js | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/client.js b/src/client.js index 1da561e75..41aaba208 100644 --- a/src/client.js +++ b/src/client.js @@ -175,6 +175,8 @@ function MatrixClient(opts) { this._cryptoStore = opts.cryptoStore; this._sessionStore = opts.sessionStore; + this._forceTURN = opts.forceTURN || false; + if (CRYPTO_ENABLED) { this.olmVersion = Crypto.getOlmVersion(); } @@ -252,6 +254,15 @@ MatrixClient.prototype.supportsVoip = function() { return this._supportsVoip; }; +/** + * Set whether VoIP calls are forced to use only TURN + * candidates. This is the same as the forceTURN option + * when creating the client. + */ +MatrixClient.prototype.setForceTURN = function(forceTURN) { + return this._forceTURN = forceTURN; +}; + /** * Get the current sync state. * @return {?string} the sync state, which may be null. @@ -3153,7 +3164,9 @@ function setupCallEventHandler(client) { ); } - call = webRtcCall.createNewMatrixCall(client, event.getRoomId()); + call = webRtcCall.createNewMatrixCall(client, event.getRoomId(), { + forceTURN: client._forceTURN, + }); if (!call) { console.log( "Incoming call ID " + content.call_id + " but this client " + diff --git a/src/webrtc/call.js b/src/webrtc/call.js index a44e18ad6..2de5fdcf7 100644 --- a/src/webrtc/call.js +++ b/src/webrtc/call.js @@ -1300,7 +1300,7 @@ module.exports.setVideoInput = function(deviceId) { videoInput = deviceId; }; * @param {boolean} options.forceTURN whether relay through TURN should be forced. * @return {MatrixCall} the call or null if the browser doesn't support calling. */ -module.exports.createNewMatrixCall = function(client, roomId, options) { +module.exports.createNewMatrixCall = function(client, roomId) { const w = global.window; const doc = global.document; if (!w || !doc) { @@ -1357,7 +1357,7 @@ module.exports.createNewMatrixCall = function(client, roomId, options) { roomId: roomId, turnServers: client.getTurnServers(), // call level options - forceTURN: options ? options.forceTURN : false, + forceTURN: client._forceTURN, }; return new MatrixCall(opts); }; From 40cbd5ec9deb27d5987ca5f3af2f56ce0afea0d2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 17 Nov 2017 15:03:12 +0000 Subject: [PATCH 2/5] Honour old forceTURN option for now --- src/webrtc/call.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/webrtc/call.js b/src/webrtc/call.js index 2de5fdcf7..9cbee4e8b 100644 --- a/src/webrtc/call.js +++ b/src/webrtc/call.js @@ -1296,11 +1296,11 @@ module.exports.setVideoInput = function(deviceId) { videoInput = deviceId; }; * Create a new Matrix call for the browser. * @param {MatrixClient} client The client instance to use. * @param {string} roomId The room the call is in. - * @param {Object?} options optional options map. - * @param {boolean} options.forceTURN whether relay through TURN should be forced. + * @param {Object?} options DEPRECATED optional options map. + * @param {boolean} options.forceTURN DEPRECATED whether relay through TURN should be forced. This option is deprecated - use opts.forceTURN when creating the matrix client since it's only possible to set this option on outbound calls. * @return {MatrixCall} the call or null if the browser doesn't support calling. */ -module.exports.createNewMatrixCall = function(client, roomId) { +module.exports.createNewMatrixCall = function(client, roomId, options) { const w = global.window; const doc = global.document; if (!w || !doc) { @@ -1350,6 +1350,9 @@ module.exports.createNewMatrixCall = function(client, roomId) { !webRtc.RtcPeerConnection || !webRtc.getUserMedia) { return null; // WebRTC is not supported. } + + const optionsForceTURN = options ? options.forceTURN : false; + const opts = { webRtc: webRtc, client: client, @@ -1357,7 +1360,7 @@ module.exports.createNewMatrixCall = function(client, roomId) { roomId: roomId, turnServers: client.getTurnServers(), // call level options - forceTURN: client._forceTURN, + forceTURN: client._forceTURN || optionsForceTURN, }; return new MatrixCall(opts); }; From eb2d5484b8d78bb35b08a73d3a61c9d697900aa9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 17 Nov 2017 15:31:50 +0000 Subject: [PATCH 3/5] jsdoc and remove pointless return --- src/client.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 41aaba208..8baa04f0a 100644 --- a/src/client.js +++ b/src/client.js @@ -258,9 +258,10 @@ MatrixClient.prototype.supportsVoip = function() { * Set whether VoIP calls are forced to use only TURN * candidates. This is the same as the forceTURN option * when creating the client. + * @param {bool} forceTURN True to force use of TURN servers */ MatrixClient.prototype.setForceTURN = function(forceTURN) { - return this._forceTURN = forceTURN; + this._forceTURN = forceTURN; }; /** From f25324fb1c6f1da893bd2722033ecf1b25234d8b Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 17 Nov 2017 15:55:20 +0000 Subject: [PATCH 4/5] Prepare changelog for v0.9.1 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c90bf35f0..3bd035f27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +Changes in [0.9.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.9.1) (2017-11-17) +================================================================================================ +[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.9.0...v0.9.1) + + * Fix the force TURN option + [\#577](https://github.com/matrix-org/matrix-js-sdk/pull/577) + Changes in [0.9.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.9.0) (2017-11-15) ================================================================================================ [Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.9.0-rc.1...v0.9.0) From 5b1a5b7dd0b5614c35a1d6279b6385236ab39c16 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 17 Nov 2017 15:55:21 +0000 Subject: [PATCH 5/5] v0.9.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d13469c13..0e8597b05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-js-sdk", - "version": "0.9.0", + "version": "0.9.1", "description": "Matrix Client-Server SDK for Javascript", "main": "index.js", "scripts": {