11.05.2020, 11:19
(11.05.2020, 06:52)admin Wrote: You need to modify the upgrade_request function in websocket library:
Code:local upgrade_request = function(req, key) local format = string.format local lines = { format('GET %s HTTP/1.1',req.path or ''), format('Host: %s',req.host), 'Upgrade: websocket', 'Connection: Upgrade', format('Sec-WebSocket-Key: %s',key), 'Sec-WebSocket-Version: 13', } if self.protocol then tinsert(lines, format('Sec-WebSocket-Protocol: %s', self.protocol)) end if req.port and req.port ~= 80 then lines[2] = format('Host: %s:%d',req.host,req.port) end if req.userinfo then local auth = format('Authorization: Basic %s', base64enc(req.userinfo)) tinsert(lines, auth) end tinsert(lines,'\r\n') return tconcat(lines,'\r\n') end
Then create connection like this (change API key):
Code:ws = require('user.websocket') json = require('json') url = 'wss://door.casambi.com/v1/bridge/' client, err = ws.client('sync', 10) client.protocol = 'API-key' res, err = client:connect(url) log(res, err)
After making the changes in library, it throws the following error:-
User library websocket:292: attempt to index global 'self' (a nil value)
stack traceback:
User library websocket:292: in function 'upgrade_request'
User library websocket:462: in function 'connect'
User script:8: in main chunk