Advertisement
osmarks

Untitled

Nov 10th, 2019
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local key = settings.get "lasers.key"
  2. if not key then error "SPUDNET key for laser control not found." end
  3. local ws, err = http.websocket("wss://osmarks.tk/wsthing/lasers/admin", {
  4.     authorization = "Key " .. key
  5. })
  6.  
  7. if err then
  8.     error(err)
  9. else
  10.     print "Connected"
  11. end
  12.  
  13. function readWS()
  14.     while true do
  15.         local txt = ws.receive()
  16.         print(txt)
  17.     end
  18. end
  19.  
  20. function send(msg)
  21.     local ok = ws.send(msg)
  22. end
  23.  
  24. function writeWS()
  25.     local hist = {}
  26.     while true do
  27.         write "|> "
  28.         local input = read(nil, hist)
  29.         table.insert(hist, input)
  30.         send(input)
  31.         sleep(0.1)
  32.     end
  33. end
  34.  
  35. local function terminateHandler()
  36.     coroutine.yield "terminate"
  37.     pcall(ws.close)
  38. end
  39.  
  40. parallel.waitForAll(writeWS, readWS, terminateHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement