-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientSoc.js
43 lines (35 loc) · 1.1 KB
/
clientSoc.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
var ip ="192.168.29.173";
var url = "ws://"+ip+":5678";
const wsc = new WebSocket(url);
// ws.onmessage =function (event){
// console.log(event.data);
// }
// wsc.on('connect',function(){
// console.log('connect client');
// // socket.emit('ehlo', data);
// });
wsc.onopen = function (event) {
wsc.send(JSON.stringify({type: 1, url:window.location.pathname.split('/')[2]}));
};
function sendData(data,curpos, insertType, selectEnd,cursorBeforePaste){
// console.log("send");
// wsc.addEventListener('open', function (event) {
// wsc.send(data);
// });
// console.log();
wsc.send(JSON.stringify({type:2, si:curpos, op:insertType, se:selectEnd, cbp:cursorBeforePaste, data:data,url:window.location.pathname.split('/')[2] }));
}
wsc.onmessage = function (event) {
let message = JSON.parse(event.data);
console.log("r on c: " + message.data);
if(typeof message.data !== 'undefined')
{
getpo();
document.getElementById('code').value=message.data;
setCursor(message);
}
}
wsc.onerror = function(event) {
console.error("WebSocket cl error observed:", event);
};
// wsc.send('hello ji');