Permalink
Browse files

preparing for socket.io data encoding optimization

  • Loading branch information...
1 parent 5d9c65b commit 62d63d91ac6ba893803da32c221ef73ea9180157 @rejetto committed Jul 4, 2012
Showing with 23 additions and 9 deletions.
  1. +7 −1 admin-server.js
  2. +3 −0 lib/serving.js
  3. +2 −1 static/backend/main.js
  4. +8 −7 static/backend/vfs.js
  5. +3 −0 static/misc.js
View
@@ -90,6 +90,7 @@ serving.setupSocketIO(io);
io.sockets.on('connection', function(socket){
socket.on('vfs.get', function onGet(data, cb) {
+ serving.ioData(data);
if (serving.ioError(!data ? data
: typeof data.uri != 'string' ? 'uri'
: null, cb)) return;
@@ -101,6 +102,7 @@ io.sockets.on('connection', function(socket){
// set properties of a vfs item
socket.on('vfs.set', function onSet(data, cb){
+ serving.ioData(data);
// assertions
if (serving.ioError(!data ? 'data'
: typeof data.uri != 'string' ? 'uri'
@@ -126,6 +128,7 @@ io.sockets.on('connection', function(socket){
// add an item to the vfs
socket.on('vfs.add', function onAdd(data, cb){
+ serving.ioData(data);
// assertions
if (serving.ioError(!data ? 'data'
: typeof data.uri !== 'string' ? 'uri'
@@ -151,6 +154,7 @@ io.sockets.on('connection', function(socket){
// delete item, make it non-existent in the VFS
socket.on('vfs.delete', function onRemove(data, cb){
+ serving.ioData(data);
// assertions
if (serving.ioError(!data ? 'data'
: typeof data.uri !== 'string' ? 'uri'
@@ -175,6 +179,7 @@ io.sockets.on('connection', function(socket){
// restore a temp item that was deleted
socket.on('vfs.restore', function onRestore(data, cb){
+ serving.ioData(data);
// assertions
if (serving.ioError(!data ? 'data'
: typeof data.uri !== 'string' ? 'uri'
@@ -204,6 +209,7 @@ io.sockets.on('connection', function(socket){
});
socket.on('info.get', function onInfo(data, cb){
+ serving.ioData(data);
serving.ioOk(cb, {caseSensitiveFileNames:misc.caseSensitiveFileNames});
});
@@ -212,7 +218,7 @@ io.sockets.on('connection', function(socket){
notifyVfsChange = function(socket, uri) {
dbg('vfs.changed');
[socket.broadcast, require('./file-server').io.sockets].forEach(function(o){
- o.emit('vfs.changed', {uri:uri});
+ o.emit('vfs.changed', serving.ioData({uri:uri}));
});
}; // notifyVfsChange
View
@@ -79,3 +79,6 @@ exports.setupSocketIO = function(io) {
, 'jsonp-polling'
]);*/
}; // setupSocketIO
+
+/** for now it's only a place-holder. We'll be able to transform data in a way to optimize socket.io communications */
+exports.ioData = function(x) { return x }
View
@@ -24,12 +24,13 @@ $(function(){ // dom ready
vfsUpdateButtons();
setupEventHandlers();
socket.on('connect', function(){ // socket ready
- socket.emit('info.get', {}, function(data){
+ socket.emit('info.get', ioData({}), function(data){
serverInfo = data||{};
reloadVFS();
});
});
socket.on('vfs.changed', function(data){
+ ioData(data);
if (!log('vfs.changed',data)) return; // something wrong
var folder = data.uri.substr(0, data.uri.lastIndexOf('/')+1);
var it = getItemFromURI(folder);
View
@@ -7,7 +7,7 @@ function bindItem() {
if (!it) return;
inputBox('Enter path', function(s){
if (!s) return;
- socket.emit('vfs.set', { uri:getURI(it), resource:s }, function(result){
+ socket.emit('vfs.set', ioData({ uri:getURI(it), resource:s }), function(result){
result.ok
? reloadVFS(it)
: msgBox(result.error);
@@ -21,7 +21,7 @@ function renameItem() {
inputBox('Enter new name', it.name, function(s){
s = $.trim(s);
if (!s || s == it.name) return; // no change
- socket.emit('vfs.set', { uri:getURI(it), name:s }, function(result){
+ socket.emit('vfs.set', ioData({ uri:getURI(it), name:s }), function(result){
if (!result.ok) {
msgBox(result.error);
return;
@@ -53,7 +53,7 @@ function deleteItem() {
li.attr('deleting',1).fadeTo(100, 0.5); // mark it visually and at DOM level
vfsSelectNearby(li); // renew selection
// server, please do it
- socket.emit('vfs.delete', { uri:getURI(it) }, function(result){
+ socket.emit('vfs.delete', ioData({ uri:getURI(it) }), function(result){
if (!log('vfs.delete',result).ok) { // something went wrong
// ugh, forget it.... (unmark)
it.deleting = false;
@@ -83,7 +83,7 @@ function restoreItem(it) {
var li = $(it.element);
var folder = li.closest('li.item');
vfsSelectNearby(li);
- socket.emit('vfs.restore', { uri:getURI(folder), resource:it.name }, function(result){
+ socket.emit('vfs.restore', ioData({ uri:getURI(folder), resource:it.name }), function(result){
if (!result.ok) return;
// do the job locally: remove the element from the array
removeFromDeletedItems(asItem(folder), it.name);
@@ -98,7 +98,7 @@ function restoreItem(it) {
function restoreAllItems(li) {
assert(li, 'li');
li = li.closest('li.item');
- socket.emit('vfs.restore', { uri:getURI(li), resource:'*' }, function(result){
+ socket.emit('vfs.restore', ioData({ uri:getURI(li), resource:'*' }), function(result){
if (!result.ok) return;
reloadVfs(li);
});
@@ -108,7 +108,7 @@ function addItem() {
var it = getFirstSelectedFolder() || getRootItem();
inputBox('Enter name or path', function(s){
if (!s) return;
- socket.emit('vfs.add', { uri:getURI(it), resource:s }, function(result){
+ socket.emit('vfs.add', ioData({ uri:getURI(it), resource:s }), function(result){
if (!log('vfs.add',result).ok) {
msgBox(result.error);
return;
@@ -442,10 +442,11 @@ function enableButton(name, condition) {
function reloadVFS(item, cb) {
var e = item ? asLI(item) : getRoot();
- socket.emit('vfs.get', { uri:item ? getURI(item) : '/', depth:1 }, function(data){
+ socket.emit('vfs.get', ioData({ uri:item ? getURI(item) : '/', depth:1 }), function(data){
if (!log('vfs.get',data)) return;
bindItemToDOM(data, e);
setExpanded(e);
+ //*** add deleted items
if (data.children.length) {
data.children.forEach(function(it){
addItemUnder(e, it);
View
@@ -194,6 +194,9 @@ function basename(path) {
function dirname(path) { return path.substr(0, path.length-basename(path)) }
+/** for now it's only a place-holder. We'll be able to transform data in a way to optimize socket.io communications */
+function ioData(x) { return x }
+
/* CURRENTLY UNUSED
// reports how many pixels the element is exceeding the viewport, on the right side

0 comments on commit 62d63d9

Please sign in to comment.