Timeslider is working

This commit is contained in:
Peter 'Pita' Martischka 2011-06-20 15:37:41 +01:00
parent 44aa476ec0
commit 867525945d
7 changed files with 84 additions and 88 deletions

View File

@ -68,6 +68,10 @@ exports.handleMessage = function(client, message)
{ {
handleClientReady(client, message); handleClientReady(client, message);
} }
else if(message.type == "CHANGESET_REQ")
{
handleChangesetRequest(client, message);
}
//if the message type is unkown, throw an exception //if the message type is unkown, throw an exception
else else
{ {
@ -85,6 +89,24 @@ function handleClientReady(client, message)
}) })
} }
function handleChangesetRequest(client, message)
{
var granularity = message.data.granularity;
var start = message.data.start;
var end = start + (100 * granularity);
var padId = message.padId;
getChangesetInfo(padId, start, end, granularity, function(err, changesetInfo)
{
if(err) throw err;
var data = changesetInfo;
data.requestID = message.data.requestID;
client.send({type: "CHANGESET_REQ", data: data});
});
}
function createTimesliderClientVars (padId, callback) function createTimesliderClientVars (padId, callback)
{ {
var clientVars = { var clientVars = {

View File

@ -9,7 +9,7 @@
], ],
"dependencies" : { "dependencies" : {
"socket.io" : "0.6.18", "socket.io" : "0.6.18",
"ueberDB" : "0.0.7", "ueberDB" : "0.0.8",
"async" : "0.1.9", "async" : "0.1.9",
"joose" : "3.18.0", "joose" : "3.18.0",
"express" : "2.3.10", "express" : "2.3.10",

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
static/img/pause.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -103,7 +103,7 @@ function loadBroadcastJS()
var userId = "hiddenUser" + randomString(); var userId = "hiddenUser" + randomString();
var socketId; var socketId;
var socket; //var socket;
var channelState = "DISCONNECTED"; var channelState = "DISCONNECTED";
@ -406,12 +406,13 @@ function loadBroadcastJS()
})); }));
} }
var changesetLoader = { global.changesetLoader = {
running: false, running: false,
resolved: [], resolved: [],
requestQueue1: [], requestQueue1: [],
requestQueue2: [], requestQueue2: [],
requestQueue3: [], requestQueue3: [],
reqCallbacks: [],
queueUp: function (revision, width, callback) queueUp: function (revision, width, callback)
{ {
if (revision < 0) revision = 0; if (revision < 0) revision = 0;
@ -448,7 +449,26 @@ function loadBroadcastJS()
var granularity = request.res; var granularity = request.res;
var callback = request.callback; var callback = request.callback;
var start = request.rev; var start = request.rev;
debugLog("loadinging revision", start, "through ajax"); var requestID = Math.floor(Math.random()*100000);
/*var msg = { "component" : "timeslider",
"type":"CHANGESET_REQ",
"padId": padId,
"token": token,
"protocolVersion": 2,
"data"
{
"start": start,
"granularity": granularity
}};
socket.send(msg);*/
sendSocketMsg("CHANGESET_REQ",{ "start": start, "granularity": granularity, "requestID": requestID});
self.reqCallbacks[requestID] = callback;
/*debugLog("loadinging revision", start, "through ajax");
$.getJSON("/ep/pad/changes/" + clientVars.padIdForUrl + "?s=" + start + "&g=" + granularity, function (data, textStatus) $.getJSON("/ep/pad/changes/" + clientVars.padIdForUrl + "?s=" + start + "&g=" + granularity, function (data, textStatus)
{ {
if (textStatus !== "success") if (textStatus !== "success")
@ -459,7 +479,19 @@ function loadBroadcastJS()
self.handleResponse(data, start, granularity, callback); self.handleResponse(data, start, granularity, callback);
setTimeout(self.loadFromQueue, 10); // load the next ajax function setTimeout(self.loadFromQueue, 10); // load the next ajax function
}); });*/
},
handleSocketResponse: function (message)
{
var self = changesetLoader;
var start = message.data.start;
var granularity = message.data.granularity;
var callback = self.reqCallbacks[message.data.requestID];
delete self.reqCallbacks[message.data.requestID];
self.handleResponse(message.data, start, granularity, callback);
setTimeout(self.loadFromQueue, 10);
}, },
handleResponse: function (data, start, granularity, callback) handleResponse: function (data, start, granularity, callback)
{ {
@ -561,7 +593,7 @@ function loadBroadcastJS()
})); }));
} }
function setUpSocket() /*function setUpSocket()
{ {
// required for Comet // required for Comet
if ((!$.browser.msie) && (!($.browser.mozilla && $.browser.version.indexOf("1.8.") == 0))) if ((!$.browser.msie) && (!($.browser.mozilla && $.browser.version.indexOf("1.8.") == 0)))
@ -607,7 +639,7 @@ function loadBroadcastJS()
{ {
abandonConnection("initsocketfail"); abandonConnection("initsocketfail");
} }
} }*/
function setChannelState(newChannelState, moreInfo) function setChannelState(newChannelState, moreInfo)
{ {

View File

@ -346,16 +346,16 @@ function loadBroadcastSliderJS()
{ {
var self = this; var self = this;
$(self).css('background-image', 'url(/static/img/pad/timeslider/crushed_button_depressed.png)'); $(self).css('background-image', 'url(/static/img/crushed_button_depressed.png)');
$(self).mouseup(function (evt2) $(self).mouseup(function (evt2)
{ {
$(self).css('background-image', 'url(/static/img/pad/timeslider/crushed_button_undepressed.png)'); $(self).css('background-image', 'url(/static/img/crushed_button_undepressed.png)');
$(self).unbind('mouseup'); $(self).unbind('mouseup');
BroadcastSlider.playpause(); BroadcastSlider.playpause();
}); });
$(document).mouseup(function (evt2) $(document).mouseup(function (evt2)
{ {
$(self).css('background-image', 'url(/static/img/pad/timeslider/crushed_button_undepressed.png)'); $(self).css('background-image', 'url(/static/img/crushed_button_undepressed.png)');
$(document).unbind('mouseup'); $(document).unbind('mouseup');
}); });
}); });

View File

@ -51,11 +51,10 @@
return "t." + randomstring; return "t." + randomstring;
} }
/*var padId, token; var socket, token, padId;
$(document).ready(function() $(window).load(function ()
{ {
//find out the padId
var urlParts= document.URL.split("/"); var urlParts= document.URL.split("/");
padId = urlParts[urlParts.length-2]; padId = urlParts[urlParts.length-2];
@ -74,53 +73,9 @@
socket = new io.Socket(); socket = new io.Socket();
socket.connect(); socket.connect();
socket.on('connect', function(){
var msg = { "component" : "timeslider",
"type":"CLIENT_READY",
"padId": padId,
"token": token,
"protocolVersion": 2};
socket.send(msg);
});
socket.on('message', function(message)
{
console.log(message);
clientVars = message.data;
initalizeWithClientVars();
})
});*/
$(window).load(function ()
{
var urlParts= document.URL.split("/");
var padId = urlParts[urlParts.length-2];
//set the title
document.title = document.title + " | " + padId;
//ensure we have a token
var token = readCookie("token");
if(token == null)
{
token = randomString();
createCookie("token", token, 60);
}
//build up the socket io connection
var socket = new io.Socket();
socket.connect();
socket.on('connect', function() socket.on('connect', function()
{ {
var msg = { "component" : "timeslider", sendSocketMsg("CLIENT_READY", {});
"type":"CLIENT_READY",
"padId": padId,
"token": token,
"protocolVersion": 2};
socket.send(msg);
}); });
socket.on('message', function(message) socket.on('message', function(message)
@ -131,11 +86,26 @@
{ {
handleClientVars(message); handleClientVars(message);
} }
else if(message.type == "CHANGESET_REQ")
{
changesetLoader.handleSocketResponse(message);
//alert("answer!")
}
}); });
//handleClientVars({data: clientVars});
}); });
function sendSocketMsg(type, data)
{
var msg = { "component" : "timeslider",
"type": type,
"data": data,
"padId": padId,
"token": token,
"protocolVersion": 2};
socket.send(msg);
}
var fireWhenAllScriptsAreLoaded = []; var fireWhenAllScriptsAreLoaded = [];
function handleClientVars(message) function handleClientVars(message)
@ -151,34 +121,6 @@
{ {
fireWhenAllScriptsAreLoaded[i](); fireWhenAllScriptsAreLoaded[i]();
} }
/*var scriptsToLoad = 3;
var loadCallback = function(info)
{
scriptsToLoad--;
console.log(scriptsToLoad);
if(scriptsToLoad == 1)
{
$.getScript('/static/js/broadcast.js', loadCallback);
}
//if all scripts are loaded
if(scriptsToLoad == 0)
{
console.log("execute!");
for(var i=0;i < fireWhenAllScriptsAreLoaded.length;i++)
{
fireWhenAllScriptsAreLoaded[i]();
}
}
}*/
//$.getScript('/static/js/broadcast_slider.js', loadCallback);
//$.getScript('/static/js/broadcast_revisions.js', loadCallback);
} }
// ]]> // ]]>