Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #161 from grey-software/issue160
Browse files Browse the repository at this point in the history
Fixed issue #160 and some bugs in distributed streaming introduced after last PR
  • Loading branch information
Ali Raza authored Feb 10, 2020
2 parents 7deb514 + 3efda44 commit 5903395
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 46 deletions.
40 changes: 19 additions & 21 deletions backend/NetworkTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ class NetworkTree {
* @returns {NetworkTree} the saved tree in transferring nodes list with same socket id at the root node
*/
isReconnecting(socketID) {
for(var i = 0; i < this.reconnectingNodes.length; i++) {
if(socketID === this.reconnectingNodes[i].node.socketID) {
return this.reconnectingNodes[i];
}
var returnNode = this.reconnectingNodes.filter((node) => node.socketID === socketID );
if(returnNode.length > 0) {
return returnNode[0];
}

return null;
}

Expand All @@ -53,11 +51,11 @@ class NetworkTree {
*/
notifyChildren(socket, node, room, root) {
var socketIDs = [];
for(var i = 0; i < node.childNodes.length; i++) {
socketIDs.push(node.childNodes[i].node.socketID);
root.reconnectingNodes.push(node.childNodes[i]);
}

node.childNodes.forEach((childNode) => {
socketIDs.push(childNode.node.socketID);
root.reconnectingNodes.push(childNode);
});
if(socketIDs.length > 0) { socket.to(room).emit("reconnect", { socketIDs }); }
}

Expand All @@ -69,13 +67,18 @@ class NetworkTree {
removeNode(socket, socketID, room, root) {
if(this.childNodes.length === 0) { return; }

for(var i = 0; i < this.childNodes.length; i++) {
if(this.childNodes[i].node.socketID === socketID) {
this.notifyChildren(socket, this.childNodes.splice(i, 1)[0], room, root);
var childIndex = -1;
this.childNodes.forEach((childNode, index) => {
if(childNode.node.socketID === socketID) {
childIndex = index;
return;
}

this.childNodes[i].removeNode(socket, socketID, room, root);
childNode.removeNode(socket, socketID, room, root);
});

if(childIndex !== -1) {
this.notifyChildren(socket, this.childNodes.splice(childIndex, 1)[0], room, root);
}
}

Expand Down Expand Up @@ -107,10 +110,7 @@ class NetworkTree {
currNode.childNodes.push(new NetworkTree(socketID, maxClients));
return true;
}

for(var i = 0; i < currNode.childNodes.length; i++) {
nodeQueue.enqueue(currNode.childNodes[i]);
}
currNode.childNodes.forEach((childNode) => nodeQueue.enqueue(childNode));
}

return false;
Expand All @@ -134,9 +134,7 @@ class NetworkTree {

if(currNode.hasSpace()) { hostPool.push(currNode.node); }

for(var i = 0; i < currNode.childNodes.length; i++) {
nodeQueue.enqueue(currNode.childNodes[i]);
}
currNode.childNodes.forEach((node) => nodeQueue.enqueue(node) );
}

return hostPool;
Expand Down
2 changes: 1 addition & 1 deletion client/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Vue.config.productionTip = false;
// ATTN: Uncomment accordingly for local/remote dev
const ENDPOINT = "https://www.toonin.ml:443/";
const socket = io(ENDPOINT, { secure: true });
// var socket = io("http://127.0.0.1:8100");
// var socket = io("http://127.0.0.1:8443");

window.onunload = () => {
if(store.getters.ROOM.length > 0) {
Expand Down
19 changes: 13 additions & 6 deletions deployment/NetworkTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class NetworkTree {
socketIDs.push(childNode.node.socketID);
root.reconnectingNodes.push(childNode);
});

if(socketIDs.length > 0) { socket.to(room).emit("reconnect", { socketIDs }); }
}

Expand All @@ -66,13 +66,20 @@ class NetworkTree {
*/
removeNode(socket, socketID, room, root) {
if(this.childNodes.length === 0) { return; }
this.childNodes.forEach((node) => {
if(node.socketID === socketID) {
this.notifyChildren(socket, node, room, root);
} else {
node.removeNode(socket, socketID, room, root);

var childIndex = -1;
this.childNodes.forEach((childNode, index) => {
if(childNode.node.socketID === socketID) {
childIndex = index;
return;
}

childNode.removeNode(socket, socketID, room, root);
});

if(childIndex !== -1) {
this.notifyChildren(socket, this.childNodes.splice(childIndex, 1)[0], room, root);
}
}

/**
Expand Down
13 changes: 7 additions & 6 deletions deployment/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ io.on("connection", socket => {

socket.on("new peer", (roomID) => {
const room = roomManager.getRoom(roomID);

if(room){
if(room.getConnectableNodes) {
const potentialHosts = room.getConnectableNodes();
if(room.room.getConnectableNodes) {
const potentialHosts = room.room.getConnectableNodes();
socket.emit("host pool", { potentialHosts, roomID });
} else {
socket.join(roomID, () => {
Expand Down Expand Up @@ -91,8 +92,8 @@ io.on("connection", socket => {
socket.to(descData.room).emit("peer desc", descData);

const room = roomManager.getRoom(descData.room);
if(room.addNode) {
room.addNode(descData.id, MAX_CLIENTS_PER_HOST, descData.selectedHost);
if(room.room.addNode) {
room.room.addNode(descData.id, MAX_CLIENTS_PER_HOST, descData.selectedHost);
}
});

Expand All @@ -104,8 +105,8 @@ io.on("connection", socket => {
socket.on("logoff", (req) => {
const room = roomManager.getRoom(req.room);
if(room) {
if(room.removeNode) {
room.removeNode(socket, req.socketID, req.room, room);
if(room.room.removeNode) {
room.room.removeNode(socket, req.socketID, req.room, room.room);
}

if(socket.id === req.socketID) { socket.leave(req.room); }
Expand Down
24 changes: 12 additions & 12 deletions extension/src/js/background/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*global chrome*/
// used by client.
import opus from './opus';

var lastFPSSetting = 30;
// ATTN: Uncomment accordingly for local/remote dev
const ENDPOINT = "https://www.toonin.ml:443/";
const socket = io(ENDPOINT, { secure: true });
// var socket = io("http://127.0.0.1:8100");
// var socket = io("http://127.0.0.1:8443");

var remoteDestination,
audioSourceNode,
Expand Down Expand Up @@ -81,28 +81,24 @@ chrome.runtime.onConnect.addListener(function (p) {
}
if(msg.type === "toggleScreenShare") {
constraints.video = msg.isSharing;
if(!msg.isSharing) {
lastFPSSetting = constraints.videoConstraints.mandatory.minFrameRate;
constraints.videoConstraints = null;
} else {
constraints.videoConstraints = { mandatory: { minFrameRate: lastFPSSetting } }
}
}
if(msg.type === "toggleDistributedStreaming") {
useDistributedStreaming = msg.useDistributedStreaming;
}
if(msg.type === "toggle60Fps") {
if(constraints.videoConstraints !== null) {
constraints.videoConstraints.mandatory.minFrameRate = msg.selected ? 60 : 30;
}
constraints.videoConstraints.mandatory.minFrameRate = msg.selected ? 60 : 30;
}
});
});


chrome.tabs.onRemoved.addListener(function (tabId, removed) {
if (tabId === tabID) {
disconnect();
}
});


function addTitleListener() {
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) {
if (changeInfo.title && tabId === tabID) {
Expand Down Expand Up @@ -135,6 +131,7 @@ function disconnect() {
localAudioStream = null;
peerCounter = Object.keys(peers).length;
}

// sets the volume
function changeVolume(value) {
var fraction = parseInt(value, 10) / parseInt(100, 10);
Expand All @@ -146,6 +143,7 @@ function changeVolume(value) {
audioElement.volume = volume;
}
}

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.message === "extension-state") {
sendState();
Expand Down Expand Up @@ -173,7 +171,9 @@ chrome.tabs.onUpdated.addListener(function (currentTab, changeInfo) {
* capture user's tab audio for sharing with peers
*/
function getTabAudio() {
chrome.tabCapture.capture(constraints, function (stream) {
var usableConstraints = constraints.video ? constraints : { video: false, audio: true };

chrome.tabCapture.capture(usableConstraints, function (stream) {
if (! stream) {
console.error("Error starting tab capture: " + (
chrome.runtime.lastError.message || "UNKNOWN"
Expand Down

0 comments on commit 5903395

Please sign in to comment.