mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
feature(edit) add socket
This commit is contained in:
parent
7f1a85ed6c
commit
261be70cae
2 changed files with 86 additions and 7 deletions
|
|
@ -1,4 +1,4 @@
|
|||
var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuIO, Format;
|
||||
var CloudCmd, Util, DOM, CloudFunc, io, ace, DiffProto, diff_match_patch, Zip, MenuIO, Format;
|
||||
(function(CloudCmd, Util, DOM, CloudFunc) {
|
||||
'use strict';
|
||||
|
||||
|
|
@ -45,10 +45,52 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
exec.series([
|
||||
CloudCmd.View,
|
||||
load,
|
||||
Edit.show.bind(null, callback)
|
||||
Edit.show.bind(null, callback),
|
||||
function() {
|
||||
initSocket();
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
function getHost() {
|
||||
var l = location,
|
||||
href = l.origin || l.protocol + '//' + l.host;
|
||||
|
||||
return href;
|
||||
}
|
||||
|
||||
function initSocket(error) {
|
||||
var socket,
|
||||
href = getHost(),
|
||||
FIVE_SECONDS = 5000,
|
||||
patch = function(path, patch) {
|
||||
socket.emit('patch', path, patch);
|
||||
};
|
||||
|
||||
if (!error) {
|
||||
socket = io.connect(href + '/config', {
|
||||
'max reconnection attempts' : Math.pow(2, 32),
|
||||
'reconnection limit' : FIVE_SECONDS
|
||||
});
|
||||
|
||||
socket.on('connect', function() {
|
||||
Edit.save.patch = patch;
|
||||
});
|
||||
|
||||
socket.on('message', function(msg) {
|
||||
onSave(msg);
|
||||
});
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
Edit.save.patch = patchHttp;
|
||||
});
|
||||
|
||||
socket.on('err', function(error) {
|
||||
Util.log(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.show = function(callback) {
|
||||
var func = exec.ret(callback);
|
||||
|
||||
|
|
@ -310,13 +352,16 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
|
|||
});
|
||||
};
|
||||
|
||||
Edit.save.patch = function(path, patch) {
|
||||
RESTful.patch(path, patch, onSave);
|
||||
};
|
||||
Edit.save.patch = patchHttp;
|
||||
Edit.save.write = writeHttp;
|
||||
|
||||
Edit.save.write = function(path, result) {
|
||||
function patchHttp(path, patch) {
|
||||
RESTful.patch(path, patch, onSave);
|
||||
}
|
||||
|
||||
function writeHttp(path, result) {
|
||||
RESTful.write(path, result, onSave);
|
||||
};
|
||||
}
|
||||
|
||||
function doDiff(path, callback) {
|
||||
var value = Ace.getValue();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue