Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const WebSocket = require('ws');
  2. const ElapsedTime = require('elapsed-time')
  3.  
  4. var elapsed;
  5.  
  6. const headers = {
  7.   authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Ijc5MjYxOTM1MDA1IiwidXNlcl91dWlkIjoiNWY0NzkyOTItYmZhMC00MmZlLWJkNGItZjlmZmIyMjNhZjRmIiwiZXhwIjoxNTQ1Mjk5Mzk0LCJvcmlnX2lhdCI6MTU0MjcwNzM5NH0.I-fbcMx4vGDOBLLpXAAFafP6EBVUXOw2pEDHUwIf09g"
  8. };
  9.  
  10. //const ws = new WebSocket('ws://socket.limonapp.com/ws/', {headers: headers});
  11. const ws = new WebSocket('ws://dev.limonapp.com:8080/ws/', {headers: headers});
  12. //const ws = new WebSocket('ws://localhost:8080/ws/', {headers: headers});
  13.  
  14. ws.on('open', function open() {
  15.   elapsed = ElapsedTime.new().start();
  16.   console.log('Connection opened');
  17.   var a = {
  18.         "event": "IM_ALIVE",
  19.         "point": {
  20.             "type": "Point",
  21.             "coordinates": [55.33, 33.55]
  22.     }
  23.   };
  24.   ws.send(JSON.stringify(a));
  25. });
  26.  
  27. ws.on('close', function open() {
  28.   console.log('Connection error')
  29. });
  30.  
  31. ws.on('close', function open() {
  32.   console.log('Connection closed after ' + elapsed.getValue())
  33. });
  34.  
  35. ws.on('message', function incoming(data) {
  36.   console.log(data);
  37. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement