Skip to content

Commit

Permalink
fixes get_available_rooms for 0.11 api. closes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Sep 20, 2019
1 parent 751dc2c commit d0af5f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 3 additions & 11 deletions colyseus/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,9 @@ function client:init(endpoint)
end

function client:get_available_rooms(room_name, callback)
local requestId = self.requestId + 1
self.connection:send({ protocol.ROOM_LIST, requestId, room_name })

-- TODO: add timeout to cancel request.

self.rooms_available_request[requestId] = function(rooms)
self.rooms_available_request[requestId] = nil
callback(rooms)
end

self.requestId = requestId
local url = "http" .. self.hostname:sub(3) .. "matchmake/" .. room_name
local headers = { ['Accept'] = 'application/json' }
self:_request(url, 'GET', headers, nil, callback)
end

function client:loop(timeout)
Expand Down
15 changes: 14 additions & 1 deletion example/example.script
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,25 @@ ColyseusConnection.config = { connect_timeout = 10 }
--]]

function init(self)
msg.post(".", "acquire_input_focus")
msg.post(".", "acquire_input_focus")


-- Add initialization code here
-- Remove this function if not needed
client = Colyseus.new("ws://localhost:2567")

-- get all available rooms at every 3 seconds (example)
timer.delay(3, true, function()
client:get_available_rooms("", function(err, rooms)
if err then
print("get_available_rooms error =>")
pprint(err)
end
print("available rooms =>")
pprint(rooms)
end)
end)

client.auth:login(function(err, auth)
print("AUTH DATA:")
pprint(auth)
Expand Down

0 comments on commit d0af5f5

Please sign in to comment.