Skip to content

Commit

Permalink
Support special cases of Single PC (lynckia#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Apr 9, 2018
1 parent fcaa62f commit 3605077
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
16 changes: 11 additions & 5 deletions common/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ API.api.event = function(theEvent) {
var session = API.sessions_active[roomID];
if (session !== undefined) {
var stream = search(streamID, session.streams);
stream.finalPublish = finalTimestamp;
if (stream) {
stream.finalPublish = finalTimestamp;
}
}

if (API.rooms[roomID] !== undefined) {
Expand Down Expand Up @@ -331,7 +333,9 @@ API.api.event = function(theEvent) {
event.userID = userID;
event.userName = userName;

API.streams[streamID].subscribers.push(userID);
if (API.streams[streamID]) {
API.streams[streamID].subscribers.push(userID);
}

if (API.users[userID] === undefined) {
API.users[userID] = {
Expand Down Expand Up @@ -399,7 +403,9 @@ API.api.event = function(theEvent) {
var indexStream = API.streams[streamID].subscribers.indexOf(userID);
if (indexStream > -1) API.streams[streamID].subscribers.splice(indexStream, 1);

delete API.states[streamID].subscribers[userID];
if (API.states[streamID]) {
delete API.states[streamID].subscribers[userID];
}

if (API.streams[streamID].userID == userID){
delete API.streams[streamID];
Expand All @@ -420,7 +426,7 @@ API.api.event = function(theEvent) {
var streamID = theEvent.pub;
var subID = theEvent.subs;
var state = theEvent.status;
var roomID = API.streams[streamID].roomID;
var roomID = API.streams[streamID] && API.streams[streamID].roomID;

event.type = "connection_status";
event.streamID = streamID;
Expand All @@ -439,7 +445,7 @@ API.api.event = function(theEvent) {
}
subID = API.streams[streamID].userID;

} else {
} else if (API.states[streamID]) {
API.states[streamID].subscribers[subID] = state;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"debug": "~2.0.0",
"ejs": "1.0.0",
"ejs": "2.5.5",
"express": "~4.9.0",
"express-partials": "^0.3.0",
"jade": "~1.6.0",
Expand Down
5 changes: 3 additions & 2 deletions public/javascripts/publishers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var socket = io();
var view_type = "list";
var search;

$(document).ready(function(){

Expand Down Expand Up @@ -40,7 +41,7 @@ $(document).ready(function(){
search();
});

var search = function() {
search = function() {
var filter_array = new Array();
var filter = $('#searchBar')[0].value.toLowerCase(); // no need to call jQuery here
filter_array = filter.split(' '); // split the user input at the spaces
Expand Down Expand Up @@ -227,7 +228,7 @@ var paintPublishersList = function() {
if (streams[streamID] !== undefined) {
var nSubscribers = streams[streamID].subscribers.length;
var userName = streams[streamID].userName;
var state = states[streamID].state;
var state = states[streamID] && states[streamID].state;
createNewPublisherList(roomID, streamID, nSubscribers, userName, state);
}
}
Expand Down
12 changes: 5 additions & 7 deletions public/javascripts/subscribers.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ $(document).ready(function(){
for (var sub in subscribers){
var userID = subscribers[sub];
var userName = users[userID].userName;
var state = states[streamID].subscribers[userID];
var state = states[streamID] && states[streamID].subscribers[userID];

createNewSubscriberList(userID, userName, state);
}
Expand All @@ -501,16 +501,14 @@ $(document).ready(function(){
if (room) {
var roomStreams = room.streams;
for (var stream in roomStreams){
if ((streamID != roomStreams[stream]) && states[roomStreams[stream]] && streams[roomStreams[stream]]) {
var state = states[roomStreams[stream]].state;
if ((streamID != roomStreams[stream]) && streams[roomStreams[stream]]) {
var state = states[roomStreams[stream]] && states[roomStreams[stream]].state;
var userName = streams[roomStreams[stream]].userName;
createNewPublisher(roomID, roomStreams[stream], userName, state);
} else if ((streamID == roomStreams[stream]) && states[streamID] && streams[streamID]) {
if (states[streamID]){
var state = states[streamID].state;
} else if ((streamID == roomStreams[stream]) && streams[streamID]) {
var state = states[streamID] && states[streamID].state;
var userName = streams[streamID].userName;
createMyPublisher(roomID, streamID, userName, state);
}
}
}
updateStatePublisher();
Expand Down

0 comments on commit 3605077

Please sign in to comment.