forked from andersonba/yve-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
39 lines (36 loc) · 844 Bytes
/
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
var socket = io.connect('http://localhost:3000');
var chat = new YveBot([], {
target: '.Chat',
})
.on('reply', function(value) {
socket.emit('reply', {
message: value,
store: window.store,
sid: window.user,
});
})
.start();
socket
.emit('join')
.on('connected', function (user) {
window.user = user;
window.store = {};
});
socket
.on('storeChanged', function(store) {
window.store = store;
document.getElementById('output').innerText = JSON.stringify(store, null, 4);
})
.on('error', function(err) {
alert('Error! Check the console output');
console.error(err);
})
.on('talk', function (payload) {
chat.newMessage('BOT', payload.message, payload.data);
})
.on('typing', function() {
chat.typing();
})
.on('typed', function() {
chat.typed();
});