Skip to content

Commit

Permalink
Merge pull request #25 from ant-media/peerConfigFix
Browse files Browse the repository at this point in the history
change pcConfig to peerconnection_config
  • Loading branch information
mekya authored Jun 18, 2024
2 parents 40adfaa + 7e58c1e commit 58416a5
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antmedia/videojs-webrtc-plugin",
"version": "1.2.0",
"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",
Expand Down Expand Up @@ -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"
},
Expand Down
22 changes: 18 additions & 4 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
pcConfig: this.source.pcConfig,

isPlayMode: true,
sdpConstraints: this.source.sdpConstraints,
reconnectIfRequiredFlag: this.source.reconnect,
Expand Down Expand Up @@ -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);
}

/**
Expand Down
83 changes: 83 additions & 0 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,95 @@ import videojs from 'video.js';

import plugin from '../src/plugin.js';

const STATIC_VIDEO_HTML = "<video id='video-player' class='video-js vjs-default-skin vjs-big-play-centered' controls playsinline></video>";

QUnit.test('the environment is sane', function(assert) {
assert.strictEqual(typeof Array.isArray, 'function', 'es5 exists');
assert.strictEqual(typeof sinon, 'object', 'sinon exists');
assert.strictEqual(typeof videojs, 'function', 'videojs exists');
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() {
Expand All @@ -34,3 +116,4 @@ QUnit.module('videojs-webrtc-plugin', {
this.clock.restore();
}
});

0 comments on commit 58416a5

Please sign in to comment.