Dailymotion support

This commit is contained in:
calzoneman 2013-03-23 13:17:39 -05:00
parent bf72733086
commit c0fc363f1b
6 changed files with 116 additions and 6 deletions

View file

@ -199,6 +199,8 @@ function initCallbacks() {
updateSC(data);
else if(data.type == "vi")
updateVI(data);
else if(data.type == "dm")
updateDM(data);
});
socket.on('userlist', function(data) {
@ -245,6 +247,14 @@ function initCallbacks() {
});
});
}
else if(MEDIATYPE == "dm") {
socket.emit('mediaUpdate', {
id: PLAYER.mediaId,
seconds: PLAYER.currentTime,
paused: PLAYER.paused,
type: "dm"
});
}
};
}
// I'm not a leader. Don't send syncs to the server

View file

@ -81,6 +81,15 @@ tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Load the Dailymotion iframe API
/*
var tag = document.createElement('script');
tag.src = "http://api.dmcdn.net/all.js";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
*/
if(uname != null && pw != null && pw != "false") {

View file

@ -335,6 +335,32 @@ function updateSC(data) {
});
}
// Dailymotion synchronization
function updateDM(data) {
if(MEDIATYPE != "dm") {
console.log("updateDM: MEDIATYPE=", MEDIATYPE);
removeCurrentPlayer();
PLAYER = DM.player("ytapiplayer", {
video: data.id,
width: 640,
height: 390,
params: {autoplay: 1}
});
PLAYER.mediaId = data.id;
MEDIATYPE = "dm";
}
else if(PLAYER.mediaId != data.id) {
PLAYER.api("load", data.id);
PLAYER.mediaId = data.id;
}
else {
if(Math.abs(data.currentTime - PLAYER.currentTime) > SYNC_THRESHOLD) {
PLAYER.api("seek", data.currentTime);
}
}
}
// Vimeo synchronization
// URGH building a synchronizing tool is so frustrating when
// these APIs are designed to be async
@ -408,16 +434,18 @@ function removeCurrentPlayer(){
function parseVideoURL(url){
if(typeof(url) != "string")
return null;
if(url.indexOf("youtu") != -1)
if(url.indexOf("youtu.be") != -1 || url.indexOf("youtube.com") != -1)
return [parseYTURL(url), "yt"];
else if(url.indexOf("twitch") != -1)
else if(url.indexOf("twitch.tv") != -1)
return [parseTwitch(url), "tw"];
else if(url.indexOf("livestream") != -1)
else if(url.indexOf("livestream.com") != -1)
return [parseLivestream(url), "li"];
else if(url.indexOf("soundcloud") != -1)
else if(url.indexOf("soundcloud.com") != -1)
return [url, "sc"];
else if(url.indexOf("vimeo") != -1)
else if(url.indexOf("vimeo.com") != -1)
return [parseVimeo(url), "vi"];
else if(url.indexOf("dailymotion.com") != -1)
return [parseDailymotion(url), "dm"];
}
function parseYTURL(url) {
@ -470,6 +498,14 @@ function parseVimeo(url) {
return null;
}
function parseDailymotion(url) {
var m = url.match(/dailymotion\.com\/video\/([a-zA-Z0-9_-]+)/);
if(m) {
return m[1];
}
return null;
}
function closePoll() {
if($('#pollcontainer .active').length != 0) {
var poll = $('#pollcontainer .active');