Attaching extra information to your clients

Wowza API offers a very powerful way to store arbitrary extra information such as username on your connected players. In this short Wowza module tutorial article I want to share with you how do I achieve this in my Wowza modules.

Wowza API handles RTMP and HTTP clients differently, so we also need to handle these clients separately. If you have reference to a IHTTPStreamerSession instance, like you do in onHTTPSessionCreate, you can use getProperties() to get an instance of WMSProperties. This class can store key-value pairs that are associated with the player in its whole lifecycle from connection to disconnection. You can use setProperty(String key, Object value) to store Strings or any other Object.

public void onHTTPSessionCreate(IHTTPStreamerSession httpSession) {
   // do something here, such as determine the username
   httpSession.getProperties().setProperty("username", userName);

The same applies to RTMP clients, they also have this WMSProperty attached:

public void onConnectAccept(IClient client) {
    client.getProperties().setProperty("exiration", 200);

If you have a reference to IApplicationInstance, you can iterate over existing RTMP and HTTP clients and do some operation on them based on their properties:

private void dropUsersWithLetterA() {
  for(IHTTPStreamerSession client: appInstance.getHTTPStreamerSessions()) {
    String userName = client.getProperties().getProperty("username");
    if(userName.startsWith("a")) {
  // you can do a similar iteration for RTMP guys
  // for(IClient existingClient : appInstance.getClients()) { .. }

You can use getPropertyBoolean(String key, boolean defaultValue), getPropertyStr(String key, String defaultValue) etc. to conveniently access your pre-set properties with defined defaults if they were not set initially.

Write new comment