-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCollabClient.js
More file actions
133 lines (107 loc) · 3.38 KB
/
Copy pathCollabClient.js
File metadata and controls
133 lines (107 loc) · 3.38 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// --------------------------------------------------------------------------
// This is the javascript required for interactive data retrieval from
// the Max-based SocketIO (client).
// Authors: Nick Hwang, Tony T Marasco, Eric Sheffield
// Contact: nickthwang@gmail.com
// --------------------------------------------------------------------------
const maxAPI = require('max-api'),
io = require('socket.io-client'),
socket = io.connect('http://remote-collab.herokuapp.com/');
//socket = io.connect('http://localhost:3000');
socket.on('connect', () => {
maxAPI.outlet("Connected to server");
maxAPI.outlet("connected");
});
// events
maxAPI.addHandler('event', (header) => {
socket.emit('event', header);
console.log('event sent: ' + header);
maxAPI.outlet(["event", header]);
})
maxAPI.addHandler('chat', (data) => {
socket.emit('chat', data);
console.log('chat sent: ' + data);
})
maxAPI.addHandler('getEvents', () => {
socket.emit('getEvents');
console.log('getList of Events');
})
maxAPI.addHandler('clearEvents', () => {
socket.emit('clearEvents');
console.log('clearing list of Events');
})
maxAPI.addHandler('control', (head, ...vals) => {
console.log("val length: " + vals.length);
const newControl = {
header: head,
values: vals
};
console.log(newControl);
socket.emit('control', newControl);
console.log('sending control: ' + head + " - " + vals);
});
maxAPI.addHandler('clearControls', () => {
socket.emit('clearControls');
console.log('clearControls called');
});
maxAPI.addHandler('getControl', (header) => {
socket.emit('getControl', header);
console.log('requesting control: ' + header);
});
maxAPI.addHandler('addUsername', (name) => {
socket.emit('addUsername', name);
console.log('addUsername called');
});
maxAPI.addHandler('getUsers', () => {
socket.emit('getUsers');
console.log('getUsers called');
});
maxAPI.addHandler('clearUsers', () => {
socket.emit('clearUsers');
console.log('clearUsers called');
});
maxAPI.addHandler('setServerConsole', (val) =>{
socket.emit('setConsoleDisplay', val);
});
socket.on('chat', function(data){
console.log('chat message received');
maxAPI.outlet(["chat", data]);
})
socket.on('serverMessage', function(data) {
console.log('Message from Server: ' + data);
maxAPI.outlet(["serverMessage", data]);
});
socket.on('users', function(data) {
console.log('lists of users: ' + data);
// maxAPI.outlet(["users", ...data]);
maxAPI.outlet(["users", data]);
});
socket.on('event', function(header) {
console.log('received event: ' + header);
maxAPI.outlet(["event", header]);
});
socket.on('events', function(events) {
console.log('lists of events: ' + events);
maxAPI.outlet(["events", events]);
})
// socket.on('seconds', (data) => {
// console.log('seconds logged?');
// // maxAPI(outl)
// })
socket.on('control', function(head, vals) {
console.log('control ' + head + " " + vals);
// use spread operator regardless if single or multiple datum.
// console.log('val length: ' + vals);
if (vals == null || vals == 'undefined') {
console.log('header undefined');
maxAPI.outlet(["control", head, "noHeader"]);
} else {
maxAPI.outlet(["control", head, ...vals]);
}
});
socket.on('controlDump', function(obj) {
console.log('controlDump ' + obj);
//let newDict = {head k
//maxAPI.outlet(["control", head + " " + vals]);
maxAPI.outlet(["controlDump", obj]);
});