Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
enqueue 'send' messages instead of 'join'. bump v0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Mar 9, 2016
1 parent eede00c commit 48c7bef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions coronasdk-example/colyseus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ function Colyseus:close()
end

function Colyseus:send(data)
self.ws:send( msgpack.pack(data), {
type = WebSocket.BINARY
} )
if self.ws.readyState == WebSocket.ESTABLISHED then -- same as WebSocket.OPEN in JavaScript
self.ws:send( msgpack.pack(data), {
type = WebSocket.BINARY
} )

else
-- WebSocket not connected.
-- Enqueue data to be sent when readyState == OPEN
table.insert(self._enqueuedCalls, {'send', data})
end
end

function Colyseus:join(...)
Expand All @@ -68,14 +75,7 @@ function Colyseus:join(...)
self.rooms[ roomName ] = room.create(self, roomName)
end

if self.ws.readyState == WebSocket.ESTABLISHED then -- same as WebSocket.OPEN in JavaScript
self:send({ protocol.JOIN_ROOM, roomName, options or {} })

else
-- WebSocket not connected.
-- Enqueue it to be called when readyState == OPEN
table.insert(self._enqueuedCalls, {'join', args})
end
self:send({ protocol.JOIN_ROOM, roomName, options or {} })

return self.rooms[ roomName ]
end
Expand Down
4 changes: 2 additions & 2 deletions publish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# version=$(git tag -l | tail -1)

version="0.1.3"
rev="2" # rev="1"
version="0.1.4"
rev="1" # rev="1"

name="colyseus-$version-$rev"

Expand Down
22 changes: 11 additions & 11 deletions src/colyseus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ function Colyseus:close()
end

function Colyseus:send(data)
self.ws:send( msgpack.pack(data), {
type = WebSocket.BINARY
} )
if self.ws.readyState == WebSocket.ESTABLISHED then -- same as WebSocket.OPEN in JavaScript
self.ws:send( msgpack.pack(data), {
type = WebSocket.BINARY
} )

else
-- WebSocket not connected.
-- Enqueue data to be sent when readyState == OPEN
table.insert(self._enqueuedCalls, {'send', data})
end
end

function Colyseus:join(...)
Expand All @@ -68,14 +75,7 @@ function Colyseus:join(...)
self.rooms[ roomName ] = room.create(self, roomName)
end

if self.ws.readyState == WebSocket.ESTABLISHED then -- same as WebSocket.OPEN in JavaScript
self:send({ protocol.JOIN_ROOM, roomName, options or {} })

else
-- WebSocket not connected.
-- Enqueue it to be called when readyState == OPEN
table.insert(self._enqueuedCalls, {'join', args})
end
self:send({ protocol.JOIN_ROOM, roomName, options or {} })

return self.rooms[ roomName ]
end
Expand Down

0 comments on commit 48c7bef

Please sign in to comment.