-
Notifications
You must be signed in to change notification settings - Fork 3
/
tg_client.js
executable file
·63 lines (52 loc) · 1.63 KB
/
tg_client.js
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
(function(){
var TGClient = function(host) {
var self = this;
endpoint = host ||
(location.protocol + '//' + location.hostname +
(location.port ? ':' + location.port : ''));
endpoint = endpoint + '/rooms';
var socket = io.connect(endpoint); //, {reconnect: false});
this.roomName = '';
socket.on('connect', function(){
self.trigger('connect');
});
socket.on('newRoom', function(room) {
self.roomName = room;
self.trigger('newRoom', room);
console.log('Connect another browser for remote control: ' + endpoint.replace(/rooms/, '?room=' + room));
});
socket.on('clientCount', function(count) {
self.trigger('clientCount', count);
});
socket.on('click', function(id) {
self.trigger('click', id);
// console.log('click: ' + id);
});
socket.on('arrive', function(id) {
self.trigger('arrive', id);
console.log('arrive: ' + id);
});
this._socket = socket;
};
TGClient.prototype.join = function(room, callback) {
this._socket.emit('join', room, function(result) {
if (!result) {
console.error('Failed to join room: ' + room);
}
if (typeof callback === 'function') {
callback(result);
}
});
};
TGClient.prototype.click = function(id) {
this._socket.emit('click', id);
// console.log('emitted click');
};
TGClient.prototype.arrive = function(id) {
this._socket.emit('arrive', id);
// console.log('emitted arrive', id);
};
MicroEvent.mixin(TGClient);
window.TwineGang = new TGClient();
console.log('WORKIN ON A TWINE GANG');
})();