From c5539b9d440b23bdb52ab4fe1903d113165f6c4a Mon Sep 17 00:00:00 2001 From: lastpeony Date: Tue, 28 May 2024 14:01:32 +0300 Subject: [PATCH 1/3] change pcConfig to peerconnection_config --- src/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.js b/src/plugin.js index 22570ef..0fd4c43 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -97,7 +97,7 @@ class WebRTCHandler { this.webRTCAdaptor = new WebRTCAdaptor({ websocketURL: this.source.mediaServerUrl, mediaConstraints: this.source.mediaConstraints, - pcConfig: this.source.pcConfig, + peerconnection_config: this.source.pcConfig, isPlayMode: true, sdpConstraints: this.source.sdpConstraints, reconnectIfRequiredFlag: this.source.reconnect, From 700faa105c2b15fcd1644bd6445cff47c0d137db Mon Sep 17 00:00:00 2001 From: mekya Date: Tue, 18 Jun 2024 17:18:04 +0300 Subject: [PATCH 2/3] Add test codes to confirm the fix --- package.json | 4 +-- src/plugin.js | 22 +++++++++--- test/plugin.test.js | 83 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ce4ccde..dc083c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antmedia/videojs-webrtc-plugin", - "version": "1.2.0", + "version": "1.2.1", "description": "streaming via WebRTC with Ant-MediaServer", "main": "dist/videojs-webrtc-plugin.cjs.js", "module": "dist/videojs-webrtc-plugin.es.js", @@ -79,7 +79,7 @@ "README.md": "doctoc --notitle" }, "dependencies": { - "@antmedia/webrtc_adaptor": "^2.6.2-SNAPSHOT-2023-Jun-12-04-58", + "@antmedia/webrtc_adaptor": "^2.9.0", "global": "^4.4.0", "video.js": "^6 || ^7" }, diff --git a/src/plugin.js b/src/plugin.js index 0fd4c43..efb2187 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -82,7 +82,11 @@ class WebRTCHandler { this.options = videojs.mergeOptions(defaults, options); this.source = source; - this.source.pcConfig = { iceServers: JSON.parse(source.iceServers) }; + if (typeof source.iceServers === 'object') { + this.source.pcConfig = { iceServers: source.iceServers }; + } else if (typeof source.iceServers === 'string') { + this.source.pcConfig = { iceServers: JSON.parse(source.iceServers) }; + } // replace the stream name with websocket url this.source.mediaServerUrl = source.src.replace(source.src.split('/').at(-1), 'websocket'); @@ -94,10 +98,10 @@ class WebRTCHandler { this.source.subscriberCode = this.getUrlParameter('subscriberCode'); this.source.reconnect = this.source.reconnect === undefined ? true : this.source.reconnect; - this.webRTCAdaptor = new WebRTCAdaptor({ + const config = { websocketURL: this.source.mediaServerUrl, mediaConstraints: this.source.mediaConstraints, - peerconnection_config: this.source.pcConfig, + isPlayMode: true, sdpConstraints: this.source.sdpConstraints, reconnectIfRequiredFlag: this.source.reconnect, @@ -176,7 +180,17 @@ class WebRTCHandler { this.player.trigger('webrtc-error', { error }); } - }); + }; + + if (this.source.pcConfig) { + /* eslint-disable camelcase */ + const peerconnection_config = {}; + + Object.assign(peerconnection_config, this.source.pcConfig); + + Object.assign(config, { peerconnection_config }); + } + this.webRTCAdaptor = new WebRTCAdaptor(config); } /** diff --git a/test/plugin.test.js b/test/plugin.test.js index 38e6669..26c6f38 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -6,6 +6,8 @@ import videojs from 'video.js'; import plugin from '../src/plugin.js'; +const STATIC_VIDEO_HTML = ""; + QUnit.test('the environment is sane', function(assert) { assert.strictEqual(typeof Array.isArray, 'function', 'es5 exists'); assert.strictEqual(typeof sinon, 'object', 'sinon exists'); @@ -13,6 +15,86 @@ QUnit.test('the environment is sane', function(assert) { assert.strictEqual(typeof plugin, 'object', 'plugin is a object'); }); +QUnit.test('PeerConnection Config', function(assert) { + + const videoContainer = document.createElement('video_container'); + + videoContainer.innerHTML = STATIC_VIDEO_HTML; + + document.getElementById('qunit-fixture').appendChild(videoContainer); + + const element = document.getElementById('video-player'); + + assert.ok(element, 'Video Element is created'); + + { + const iceServer = '[ { "urls": "turn:ovh36.antmedia.io" } ]'; + + const webrtcHandler = new plugin.WebRTCHandler( + { + src: 'ws://localhost:5080/WebRTCAppEE/stream.webrtc', + type: 'video/webrtc', + withCredentials: true, + iceServers: iceServer, + reconnect: false + }, + null, + { + playerId: 'video-player' + } + ); + + assert.deepEqual(webrtcHandler.webRTCAdaptor.peerconnection_config.iceServers, JSON.parse(iceServer), 'PeerConnection Config is correct'); + } + + { + const iceServer2 = [ + { urls: 'turn:ovh36.antmedia.io' } + ]; + const webrtcHandler2 = new plugin.WebRTCHandler( + { + src: 'ws://localhost:5080/WebRTCAppEE/stream.webrtc', + type: 'video/webrtc', + withCredentials: true, + iceServers: [ + { urls: 'turn:ovh36.antmedia.io' } + ], + reconnect: false + }, + null, + { + playerId: 'video-player' + } + ); + + assert.deepEqual(webrtcHandler2.webRTCAdaptor.peerconnection_config.iceServers, iceServer2, 'PeerConnection Config is correct'); + } + + { + + // default iceServers + const iceServer = [{ + urls: 'stun:stun1.l.google.com:19302' + }]; + + const webrtcHandler = new plugin.WebRTCHandler( + { + src: 'ws://localhost:5080/WebRTCAppEE/stream.webrtc', + type: 'video/webrtc', + withCredentials: true, + reconnect: false + }, + null, + { + playerId: 'video-player' + } + ); + + assert.deepEqual(webrtcHandler.webRTCAdaptor.peerconnection_config.iceServers, iceServer, 'PeerConnection Config is correct'); + } + +}); + QUnit.module('videojs-webrtc-plugin', { beforeEach() { @@ -34,3 +116,4 @@ QUnit.module('videojs-webrtc-plugin', { this.clock.restore(); } }); + From 7e58c1e4972c0cf1f9855c9b3782237979e0ab17 Mon Sep 17 00:00:00 2001 From: mekya Date: Tue, 18 Jun 2024 18:35:05 +0300 Subject: [PATCH 3/3] Increase version to 1.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dc083c2..297b12a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antmedia/videojs-webrtc-plugin", - "version": "1.2.1", + "version": "1.2.2", "description": "streaming via WebRTC with Ant-MediaServer", "main": "dist/videojs-webrtc-plugin.cjs.js", "module": "dist/videojs-webrtc-plugin.es.js",