forked from mkaminsky11/codeyourcloud
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfrontend.js
More file actions
67 lines (65 loc) · 1.77 KB
/
Copy pathfrontend.js
File metadata and controls
67 lines (65 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var connection = new WebSocket('ws://64.207.146.34:8080');
var sshSession = "";
connection.onopen = function () {
console.log("open");
/*INITIALIZE*/
if(document.URL.indexOf("ssh") === -1){
websocketInit();
}
else{
}
connection.send(JSON.stringify({type: "update", name: userName}));
};
function websocketInit(){
//get the init info
connection.send(JSON.stringify({type: "request", data: "init", session: current}));
connection.send(JSON.stringify({type: "update", name: userName}));
}
connection.onmessage = function (message) {
try {
var json = JSON.parse(message.data);
if(json.type === "init"){
}
if(json.type === "command"){
if(json.command === "save"){
saveNoSend();
}
if(json.command === "rename"){
var newTitle = json.title;
document.getElementById("renameInput").value = newTitle;
okRenameNoSend();
}
if(json.command === "mode"){
var newMode = json.mode;
setModeNoSend(newMode);
}
if(json.command === "theme"){
var newTheme = json.theme;
setThemeNoSend(newTheme);
}
}
if(json.type === "update"){
//connection.send(JSON.stringify({type: "update", name: userName}));
notify(json.name);
}
} catch (e) {
//invalid json
return;
}
};
connection.onerror = function (error) {
//uh oh...
};
function sendSave(){
connection.send(JSON.stringify({type:"command", command:"save"}));
}
function sendRename(){
var newTitle = document.getElementById("renameInput").value;
connection.send(JSON.stringify({type:"command", command:"rename", title:newTitle}));
}
function sendMode(newMode){
connection.send(JSON.stringify({type:"command", command:"mode", mode: newMode}));
}
function sendTheme(newTheme){
connection.send(JSON.stringify({type:"command", command:"theme", theme: newTheme}));
}