Skip to content

Commit

Permalink
Fixed Timing problems with incoming tracks, Audio-only/Video-only sup…
Browse files Browse the repository at this point in the history
…ported now
  • Loading branch information
luvolondon authored Apr 13, 2020
1 parent 7ce3a4e commit 9c9bf84
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
50 changes: 40 additions & 10 deletions jitsirtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class JitsiRTCClient extends WebRTCInterface {
*/
this._usernameCache = {};
this._idCache = {};
this._withAudio = false;
this._withVideo = false;

}

Expand Down Expand Up @@ -125,10 +127,14 @@ class JitsiRTCClient extends WebRTCInterface {
* @return {Promise.boolean}
*/
async initialize() {

const mode = this._settings["worldSettings"]["mode"];

if (mode > 0) {
JitsiMeetJS.init(this._options);
this._withAudio = ( (mode == 1) || (mode == 3));
this._withVideo = ( (mode == 2) || (mode == 3));

console.warn("Init:" + this._withAudio + ":" + this._withVideo);
if (game.webrtc.client._withAudio || game.webrtc.client._withVideo) {
JitsiMeetJS.init(game.webrtc.client._options);
JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
game.webrtc.debug("JitsiMeetJS init");
}
Expand Down Expand Up @@ -184,10 +190,19 @@ class JitsiRTCClient extends WebRTCInterface {

client._remoteTracks[participant].push(track);
const userId = client._idCache[participant];

let trackcount = 0;
if ( client._withAudio ) trackcount++;
if ( client._withVideo ) trackcount++;

if (userId != null) {
if (client._remoteTracks[participant].length >= 1) {
game.webrtc.onUserStreamChange( userId,client.getRemoteStreamForId(participant));
if (client._remoteTracks[participant].length >= trackcount) {
console.log("Jitsi: onUserStreamChange " + userId );

if (ui.webrtc && (ui.webrtc._state == 1)) {
setTimeout( function() { game.webrtc.onUserStreamChange( userId,client.getRemoteStreamForId(participant)); }, 1000);
} else
game.webrtc.onUserStreamChange( userId,client.getRemoteStreamForId(participant));
}
} else {
console.error("JITSI: track of unknown user " + participant);
Expand All @@ -200,6 +215,8 @@ class JitsiRTCClient extends WebRTCInterface {
this.semaphore_end;

}


/**
* Handles incoming lost remote track
* @param track JitsiTrack object
Expand All @@ -213,20 +230,27 @@ class JitsiRTCClient extends WebRTCInterface {

const participant = track.getParticipantId();
const client = game.webrtc.client;
console.log("Jitsi: track type " + track.getType() + " removed " + participant );
console.log("Jitsi: track type " + track.getType() + " removed " + participant );

if (client._remoteTracks[participant] != null) {
client._remoteTracks[participant] = client._remoteTracks[participant].filter(function(value, index, arr){ return value.ssrc != track.ssrc;});

const userId = client._idCache[participant];

if (userId != null) {
if (client._remoteTracks[participant].length == 0) {
client._remoteTracks[participant] = null;
game.webrtc.onUserStreamChange( userId,null);

if (ui.webrtc && (ui.webrtc._state == 1)) {
setTimeout( function() { game.webrtc.onUserStreamChange( userId,null); }, 1000);
} else
game.webrtc.onUserStreamChange( userId,null);

} else {
game.webrtc.onUserStreamChange( userId,client.getRemoteStreamForId(participant));
if (ui.webrtc && (ui.webrtc._state == 1)) {
setTimeout( function() { game.webrtc.onUserStreamChange( userId,client.getRemoteStreamForId(participant)); }, 1000);
} else
game.webrtc.onUserStreamChange( userId,client.getRemoteStreamForId(participant));

}
}
Expand Down Expand Up @@ -476,7 +500,13 @@ class JitsiRTCClient extends WebRTCInterface {
async initLocalStream(audioSrc, videoSrc, temporary=false) {
return new Promise(async (resolve) => {

JitsiMeetJS.createLocalTracks({ devices: [ 'audio', 'video' ],resolution: 240,


let devlist = [];
if ( this._withAudio ) devlist.push( 'audio' );
if ( this._withVideo ) devlist.push( 'video' );

JitsiMeetJS.createLocalTracks({ devices: devlist,resolution: 240,
disableSimulcast: false,
p2p: {
enabled:false
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"title": "Jitsi WebRTC client",
"description": "Use Jitsi to handle A/V. Connect to jitsi.org or self-hosted server.",
"author": "Luvolondon",
"version": "0.2.5",
"version": "0.2.6",
"styles": [],
"packs": [],
"url": "https://github.com/luvolondon/fvtt-module-jitsiwebrtc",
"manifest": "https://raw.githubusercontent.com/luvolondon/fvtt-module-jitsiwebrtc/master/module.json",
"download": "https://github.com/luvolondon/fvtt-module-jitsiwebrtc/archive/v0.2.5.zip",
"download": "https://github.com/luvolondon/fvtt-module-jitsiwebrtc/archive/v0.2.6.zip",
"minimumCoreVersion": "0.5.3",
"compatibleCoreVersion": "0.5.4",
"scripts": ["jitsirtc.js","lib-jitsi-meet.min.js"]
Expand Down

0 comments on commit 9c9bf84

Please sign in to comment.