Skip to content
Boreeas edited this page Jan 11, 2015 · 6 revisions

Rtmp is the protocol which server and lobby client use to communicate.

Opening a connection

First of all, you are going to need an auth token from the loginqueue. Refer to the module's documentation for a how-to.

Subclass RtmpClient and implement the callbacks onReadException(Exception ex), onAsyncWriteException(Exception ex) and extendedOnPacket(RtmpEvent packet). If you prefer to have them as no-ops, the class DefaultRtmpClient is what you are looking for.

Create an RtmpClient object by specifiyng the target host, port, and whether a secure connection should be used:

Shard server = Shard.EUW;
RtmpClient client = new DefaultRtmpClient(server.prodUrl, Shard.RTMPS_PORT, true);

Connect the client and authenticate yourself:

client.connect();
client.authenticate(user, pass, authKey, version);

If you specify an incorrect version for authenticate, the method will fail with a ClientVersionMismatchException. ClientVersionMismatchException.getCurrentVersion() will return the current version, and you can simply call authenticate() again with this new version.

Registering channel listeners

The server occasionally send push messages to the client without specifying an invoke id. These messages will be sent over one of three channels:

  • RtmpClient.clientNewsChannel
  • RtmpClient.gameNewsChannel
  • RtmpClient.broadcastChanel

You can register an async channel listener in the form of Consumer<AsyncMessageEvent> with the addAsyncChannelListener methods. You can either just add a listener, which will accept all messages on all channels, or optionally specify a channel name or a custom filter with Predicate<AsyncMessageEvent>, which will only notify the listener of those events that pass the filter.

Calling Services

Look here for the full list of supported rtmp services.

Synchronous

The classes in rtmp.services implement synchronous calls to their respective services. The simplest way to access such a service wrapper is via RtmpClient - each Service class has an instance in there.

GameService gameService = client.gameService;
List<PracticeGame> customGames = gameService.listAllPracticeGames();

Asynchronous

If you prefer async calls, you will want to use RtmpClient.sendRpc(). By default, this method takes four arguments: The endpoint, the service, the method name and the args. Since the endpoint is always my-rtmps, an overloaded version exists, taking only service, method and args:

// 2 arguments = No arguments to async call - in this case, listAllPracticeGame takes none
int invokeId = client.sendRpc(GameService.SERVICE, "listAllPracticeGames");
InvokeCallback callback = client.getInvokeCallback(invokeId); 

// Do some other stuff

Object result = callback.waitForReply();        // Blocks until the reply arrives
result = client.waitForInvokeReply(invokeId);   // Equivalent to getInvokeCallback().waitForReply();
Clone this wiki locally