-
Notifications
You must be signed in to change notification settings - Fork 4
/
socket.js
30 lines (30 loc) · 1010 Bytes
/
socket.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
let socket = new function() {
this.io =null,
this.start = function(output,input,url,callback,nick='',game='',ch=0) {
nick = nick.length>5?nick.substring(2,10):nick;
$(input).on('keyup', function (e) {
if (e.keyCode == 13 && socket.io!=null) {
if($(input).val()=="")
return;
let msg = $(input).val();
$(input).val('');
socket.io.emit('chat',{'game':game,'ch':ch,'nick':nick,'msg':msg});
}
});
socket.io = io(url);
socket.io.on('chat', function(data) {
$(output).append($('<li>').html(data));
$(output).scrollTop($(output)[0].scrollHeight);
});
socket.io.on('chatMe', function(data) {
$(output).append($('<li>').html('<b>'+data+'</b>'));
$(output).scrollTop($(output)[0].scrollHeight);
});
socket.io.on('schedule', function(data) {
callback(data);
});
},
this.schedule = function (address) {
socket.io.emit('schedule',{'address':address});
}
}