Skip to content

Commit

Permalink
Fix ws/wss port selection. (Also makes socket.io work)
Browse files Browse the repository at this point in the history
  • Loading branch information
treeform committed Jun 18, 2020
1 parent b726fdf commit 0379b23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ws.nim
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ proc newWebSocket*(url: string, protocol: string = ""): Future[WebSocket] {.asyn
})
if ws.protocol != "":
client.headers["Sec-WebSocket-Protocol"] = ws.protocol
var res = await client.get(url)
var res = await client.get($uri)
if ws.protocol != "":
if ws.protocol != res.headers["Sec-WebSocket-Protocol"]:
raise newException(WebSocketError, "Protocols don't match")
Expand Down
11 changes: 11 additions & 0 deletions tests/socketio.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import asyncdispatch, ws

proc socketIo() {.async.} =
echo "Connecting..."
# Empty token works to get a reply.
var webSocket = await newWebSocket("wss://sockets.streamlabs.com/socket.io/?EIO=3&transport=websocket&token=")
echo "Connected!"
echo await webSocket.receiveStrPacket()
echo "Got a packet back!"

waitFor socketIo()

0 comments on commit 0379b23

Please sign in to comment.