Merge pull request #88 from MutantRabbit767/main

[FIX] WebSocket documentation and WebSocket.html test.
This commit is contained in:
Face
2025-09-14 14:00:27 +03:00
committed by GitHub
2 changed files with 6 additions and 16 deletions

View File

@@ -54,34 +54,24 @@ ws:on('open', function()
ws:send('Hello server!')
end)
ws:on('message', function(data)
trace.log('Received: ' .. data)
ws:on('message', function(message)
trace.log('Received message: ' .. message.data)
end)
ws:on('close', function(code, reason)
trace.log('WebSocket closed: ' .. code .. ' - ' .. reason)
ws:on('close', function()
trace.log('WebSocket closed.')
end)
ws:on('error', function(error)
trace.log('WebSocket error: ' .. error)
trace.log('WebSocket error: ' .. error.message)
end)
ws:send('Hello from client!')
ws:send(JSON.stringify({ type = 'chat', message = 'Hello!' }))
ws:close()
if ws.readyState == WebSocket.OPEN then
ws:send('Connected message')
end
```
**WebSocket States:**
- `WebSocket.CONNECTING` (0) - Connection in progress
- `WebSocket.OPEN` (1) - Connection established
- `WebSocket.CLOSING` (2) - Connection closing
- `WebSocket.CLOSED` (3) - Connection closed
## URL API
URL encoding and decoding utilities for handling special characters in URLs.

View File

@@ -79,7 +79,7 @@
end)
socket:on('error', function(event)
addLog('🚨 Error: ' .. (event.message or 'Unknown error'))
addLog('🚨 Error: ' .. event.message)
updateStatus('Error', 'disconnected')
connected = false
end)