Skip to content

Commit

Permalink
update mobile API
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jul 29, 2014
1 parent 5f5ddb5 commit bf956c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
12 changes: 9 additions & 3 deletions doc/mobile-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ First you need to connect to the lobby websocket, from which you'll receive the
var clientId = Math.random().toString(36).substring(2); // created and stored by the client
var socketVersion = 0; // last message version number seen on this socket. Starts at zero.

var socketUrl = 'http://socket.en.l.org:9021/lobby/socket?sri=' + clientId + '&version=' + socketVersion;
var socketUrl = 'http://socket.en.l.org:9021/lobby/socket?mobile=1&sri=' + clientId + '&version=' + socketVersion;

var socket = new WebSocket(socketUrl);
```
Expand All @@ -103,9 +103,15 @@ Response: `200 OK`
ok
```

Now you're waiting for someone to accept the seek. The response will come as a socket message.
Now you're waiting for someone to accept the seek. The response will come as a socket message:

#### FIXME - document lobby socket
```javascript
// the seek was accepted
{
"t": "redirect", // means we should move on to the game
"id": "abcdefgh1234"
}
```

## Fetch a game as a player (POV)

Expand Down
25 changes: 11 additions & 14 deletions modules/lobby/src/main/Socket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,23 @@ private[lobby] final class Socket(
case RemoveHook(hookId) => notifyVersion("hook_remove", hookId)

case JoinHook(uid, hook, game, creatorColor) =>
playerUrl(game fullIdOf creatorColor) zip
playerUrl(game fullIdOf !creatorColor) foreach {
case (creatorUrl, invitedUrl) =>
withMember(hook.uid)(notifyMember("redirect", Json.obj(
"url" -> creatorUrl,
"cookie" -> AnonCookie.json(game, creatorColor)
).noNull))
withMember(uid)(notifyMember("redirect", Json.obj(
"url" -> invitedUrl,
"cookie" -> AnonCookie.json(game, !creatorColor)
).noNull))
}
withMember(hook.uid)(notifyMember("redirect", Json.obj(
"id" -> (game fullIdOf creatorColor),
"url" -> playerUrl(game fullIdOf creatorColor),
"cookie" -> AnonCookie.json(game, creatorColor)
).noNull))
withMember(uid)(notifyMember("redirect", Json.obj(
"id" -> (game fullIdOf !creatorColor),
"url" -> playerUrl(game fullIdOf !creatorColor),
"cookie" -> AnonCookie.json(game, !creatorColor)
).noNull))

case HookIds(ids) => notifyVersion("hook_list", ids)

case lila.hub.actorApi.StreamsOnAir(html) => notifyAll(makeMessage("streams", html))
}

private def playerUrl(fullId: String) =
router ? Player(fullId) mapTo manifest[String]
private def playerUrl(fullId: String) = s"/$fullId"

private def notifyTournaments(html: String) {
notifyAll(makeMessage("tournaments", html))
Expand Down

0 comments on commit bf956c7

Please sign in to comment.