Skip to content

Commit

Permalink
Dailymotion Support!
Browse files Browse the repository at this point in the history
Dailymotion player should now be fully functional across sockets!
  • Loading branch information
kyle8998 committed Jan 25, 2018
1 parent b61481b commit 0f501bd
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 32 deletions.
79 changes: 62 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@
allowfullscreen allow="autoplay"></iframe> -->

<div>
<button id="play">Play</button>
<button id="pause">Pause</button>
<button onclick="playVideo(roomnum)" style="margin-top:.5rem" class="btn btn-primary">Play/Pause</button>

<button onclick="syncVideo(roomnum)" style="margin-top:.5rem" class="btn btn-primary">Sync</button>
Expand Down Expand Up @@ -299,11 +297,30 @@ <h2>About Vynchronize</h2>

// Calls the play/pause function
socket.on('playVideoClient', function(data) {
play()
// Calls the proper play function for the player
switch(currPlayer) {
case 0:
play()
break;
case 1:
dailyPlay()
break;
default:
console.log("Error invalid player id")
}
});

socket.on('pauseVideoClient', function(data) {
player.pauseVideo();
switch(currPlayer) {
case 0:
player.pauseVideo();
break;
case 1:
dailyPlayer.pause();
break;
default:
console.log("Error invalid player id")
}
});

// Syncs the video client
Expand All @@ -321,27 +338,55 @@ <h2>About Vynchronize</h2>
// changeVideoId(roomnum, videoId)
// }


// This brings everyone else in the same room to your time!
player.seekTo(currTime);

// Sync player state
// IF parent player was paused
if (state == -1 || state == 2)
player.pauseVideo();
// If not paused
else
player.playVideo();
// This brings everyone else in the same room to your time!
switch(currPlayer) {
case 0:
player.seekTo(currTime);
// Sync player state
// IF parent player was paused
if (state == -1 || state == 2)
player.pauseVideo();
// If not paused
else
player.playVideo();
break;

case 1:
dailyPlayer.seek(currTime);
if (state) {
dailyPlayer.pause()
}
else {
dailyPlayer.play()
}
break;

default:
console.log("Error invalid player id")
}
});

// Change video
socket.on('changeVideoClient', function(data) {
var videoId = data.videoId;
console.log("youtube video id is: "+videoId)
console.log("video id is: "+videoId)

// This changes the video
player.loadVideoById(videoId);
id = videoId

switch(currPlayer) {
case 0:
player.loadVideoById(videoId);
break;
case 1:
dailyPlayer.load(videoId, {
autoplay: true
});
break;
default:
console.log("Error invalid player id")
}

});

// Change time
Expand Down
27 changes: 19 additions & 8 deletions js/dm.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var dailyPlayer

setTimeout(function() {
console.log("whyewwefwwvrgf")
DM.init({
Expand All @@ -6,7 +8,7 @@ setTimeout(function() {
cookie: true // enable cookies to allow the server to access the session
});

var player = DM.player(document.querySelector('#player-daily'), {
dailyPlayer = DM.player(document.querySelector('#player-daily'), {
video: 'x26m1j4',
width: '640',
height: '360',
Expand All @@ -17,31 +19,31 @@ setTimeout(function() {
});


player.addEventListener('apiready', function(e) {
dailyPlayer.addEventListener('apiready', function(e) {
console.log('api ready', e);
});

player.addEventListener('error', function(e) {
dailyPlayer.addEventListener('error', function(e) {
console.log('error', e);
});

player.addEventListener('canplay', function(e) {
dailyPlayer.addEventListener('canplay', function(e) {
console.log('canplay', e);
});

player.addEventListener('canplaythrough', function(e) {
dailyPlayer.addEventListener('canplaythrough', function(e) {
console.log('canplaythrough', e);
});

player.addEventListener('progress', function(e) {
dailyPlayer.addEventListener('progress', function(e) {
console.log('progress', e);
});

player.addEventListener('ad_play', function(e) {
dailyPlayer.addEventListener('ad_play', function(e) {
console.log('ad_play', e);
});

player.addEventListener('ad_end', function(e) {
dailyPlayer.addEventListener('ad_end', function(e) {
console.log('ad_end', e);
});

Expand All @@ -56,3 +58,12 @@ document.querySelector('#pause').addEventListener('click', function() {
});

}, 1000);

// Play/pause function for dailymotion
function dailyPlay(){
if (dailyPlayer.paused){
dailyPlayer.play();
}
else
dailyPlayer.pause();
}
25 changes: 21 additions & 4 deletions js/sync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Calls the play video function on the server
function playVideo(roomnum){
// dailyPlayer.play();
socket.emit('play video', { room: roomnum });

// Doesn't work well unless called in server
Expand All @@ -8,9 +9,24 @@ function playVideo(roomnum){

// Calls the sync function on the server
function syncVideo(roomnum){
var currTime = player.getCurrentTime();
var currTime = 0
var state

switch(currPlayer) {
case 0:
currTime = player.getCurrentTime();
state = playerStatus
break;
case 1:
currTime = dailyPlayer.currentTime;
state = dailyPlayer.paused;
break;
default:
console.log("Error invalid player id")
}

var videoId = id
socket.emit('sync video', { room: roomnum, time: currTime, state: playerStatus, videoId: videoId });
socket.emit('sync video', { room: roomnum, time: currTime, state: state, videoId: videoId });
}

// Change playVideo
Expand All @@ -29,9 +45,10 @@ function changeVideoId(roomnum, id){
}

function loveLive(roomnum){
document.getElementById("inputVideoId").innerHTML = "sjk7DiH0JhQ";
var test = document.getElementById("inputVideoId").innerHTML = "sjk7DiH0JhQ";

socket.emit('change video', { room: roomnum, videoId: 'sjk7DiH0JhQ' });
// Only for YouTube testing
socket.emit('change video', { room: roomnum, videoId: 'sjk7DiH0JhQ' });
}

// Get time
Expand Down
6 changes: 3 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ io.sockets.on('connection', function(socket){
// Play video
socket.on('play video', function(data){
var roomnum = data.room
//console.log("The data"+data)
// This calls the playVideo function on the client side
io.sockets.in("room-"+roomnum).emit('playVideoClient');
});

Expand Down Expand Up @@ -171,7 +169,9 @@ io.sockets.on('connection', function(socket){
} else {
console.log("I am the host")
//socket.emit('auto sync');
socket.broadcast.to(host).emit('auto sync');

// Auto syncing is not working atm
// socket.broadcast.to(host).emit('auto sync');
}

// This is all of the rooms
Expand Down

0 comments on commit 0f501bd

Please sign in to comment.