wide/static/js/session.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-09-19 20:56:32 +04:00
// 用于保持会话,如果该通道断开,则服务器端会销毁会话状态,回收相关资源.
var sessionWS = new WebSocket(config.channel.session + '/session/ws?sid=' + config.wideSessionId);
sessionWS.onopen = function () {
console.log('[session onopen] connected');
};
sessionWS.onmessage = function (e) {
console.log('[session onmessage]' + e.data);
var data = JSON.parse(e.data);
};
sessionWS.onclose = function (e) {
console.log('[session onclose] disconnected (' + e.code + ')');
delete sessionWS;
};
sessionWS.onerror = function (e) {
console.log('[session onerror] ' + JSON.parse(e));
};
2014-09-22 19:13:07 +04:00
// 定时30 秒)保存会话内容.
setTimeout(function () {
var request = newWideRequest();
// TODO: 会话状态保存
request.currentFile = "current file"; // 当前编辑器
request.fileTree = ["1/", "2/"]; // 文件树展开状态
request.files = ["1.go", "2.go", "3.go"]; // 编辑器打开状态
$.ajax({
type: 'POST',
url: '/session/save',
data: JSON.stringify(request),
dataType: "json",
success: function (data) {
}
});
}, 30000);