-
Notifications
You must be signed in to change notification settings - Fork 2
/
client2.js
28 lines (24 loc) · 899 Bytes
/
client2.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
// let chat = require('socket.io-client')('http://localhost:3001/chat?user_id=5b9b784739a1366cb5b8ab4d&client_id=5b99f43150fd6337a4408177');
const user_id_1 = '5b9ca5f2fe0c7826f8e2a3db'
const user_id_2 = '5b9ca5f1fe0c7826f8e2a3d9'
const client_id_1 = '5b9ca5f2fe0c7826f8e2a3dc'
let chat = require('socket.io-client')('http://localhost:3001/?user_id=' + user_id_1 + '&client_id=' + client_id_1);
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', async function (line) {
chat.emit('sendPrivateMessage', {
receiverId: user_id_2,
text: await line
})
})
chat.on('connect', function () {
console.log('connected...');
});
chat.on('receivePrivateMessage', async function (data) {
console.log('-: ', await data)
});
chat.on('disconnect', function () {});