Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add swap queue #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,17 @@ <h2>Contact Me</h2>
var html = ''
if (yt.length > 0) {
for (i = 0; i < yt.length; i++) {
html += '<li class="vid-item"><div class="thumb"><a href="javascript: removeAt(' + i + ')" class="ghost-button-full-color"><i class="far fa-times-circle"></i></a><a href="javascript: playAt(' + i +
')"><img src="http://img.youtube.com/vi/' + yt[i].videoId + '/0.jpg"></a></div><a href="javascript: playAt(' + i + ')" class="desc">' + yt[i].title + '</a></li>'
html += '<li class="vid-item">'+
'<div class="thumb">'+
'<a href="javascript: removeAt(' + i + ')" class="ghost-button-full-color"><i class="far fa-times-circle"></i></a>'+
'<a href="javascript: swapQueue(' + (i + 1) + ',' + i + ')" class="ghost-button-full-color" style="margin-right: 8px;"><i class="fas fa-arrow-right"></i></a>'+
'<a href="javascript: swapQueue(' + (i - 1) + ',' + i + ')" class="ghost-button-full-color"><i class="fas fa-arrow-left"></i></a>'+
'<a href="javascript: playAt(' + i + ')">'+
'<img src="http://img.youtube.com/vi/' + yt[i].videoId + '/0.jpg">'+
'</a>'+
'</div>'+
'<a href="javascript: playAt(' + i + ')" class="desc">' + yt[i].title + '</a>'+
'</li>'
}
} else {
html += '<li class="vid-item"></li>'
Expand Down Expand Up @@ -643,6 +652,13 @@ <h2>Contact Me</h2>
})
}

function swapQueue(prevIdx, nextIdx) {
socket.emit("swap queue", {
prev: prevIdx,
next: nextIdx
});
}


// Turn off the lights!
var per = 0;
Expand Down
31 changes: 31 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,37 @@ io.sockets.on('connection', function(socket) {
);
});

//Swap queue
socket.on("swap queue", function(data) {
if (io.sockets.adapter.rooms['room-' + socket.roomnum] !== undefined) {
//Queue is only supported YouTube
if(io.sockets.adapter.rooms['room-' + socket.roomnum].currPlayer == 0) {
var prevIndex = data.prev;
var nextIndex = data.next;

console.log("swap queue (prev: " + prevIndex + ", next: " + nextIndex + ")");

//Return when array index out of bounds
var queueCount = io.sockets.adapter.rooms['room-' + socket.roomnum].queue.yt.length;
if(prevIndex == -1 || nextIndex == -1) {
return;
} else if (prevIndex >= queueCount || nextIndex >= queueCount) {
return;
}

//Get swap objects
var prevObject = io.sockets.adapter.rooms['room-' + socket.roomnum].queue.yt[prevIndex];
var nextObject = io.sockets.adapter.rooms['room-' + socket.roomnum].queue.yt[nextIndex];

//Swap
io.sockets.adapter.rooms['room-' + socket.roomnum].queue.yt[prevIndex] = nextObject;
io.sockets.adapter.rooms['room-' + socket.roomnum].queue.yt[nextIndex] = prevObject;

updateQueueVideos();
}
}
});


// Some update functions --------------------------------------------------
// Update all users
Expand Down