1. Overview
  2. Connecting to Socket.IO
  3. The Pub/Sub Model
  4. Socket.IO Implementation

1 Overview

Socket.IO is a javascript library that uses the WebSocket protocol to facilitate real time communications. Avaya Spaces uses Socket.IO to implement messaging functionality. Every message sent (chat, task, or post) is broadcast as a Socket.IO event. See the tutorial for the step-by-step walkthrough of the connection process, or see the Socket.IO reference for full documentation.

Avaya Spaces uses version 1.7.3 of Socket.IO. Client applications should ensure their implementation of Socket.IO is compatible with version 1.7.3. You can obtain the JS script here by downloading the file or linking to a CDN.

We recommend the following Socket.IO client libraries:

2 Connecting to Socket.IO

Clients are authenticated via JWT or OAuth 2 token. The tokens are simply passed to Socket.IO as an argument of the IO.connect() function. An example Socket.IO connection request is shown below.

Must set websocket only in transports explicitly.

var socketio = io.connect(
    "https://spacesapis-socket.zang.io/chat",
    {query: 'tokenType=jwt&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhbm9ueW1vdXNfaWQiOiI1NmRmMzk2MzY3NmU4Mjk0N2IyZjkyNDMiLCJwcm9kdWN0X3R5cGUiOiJvbmVzbmEiLCJpc3MiOlsiZXNuYSIsImNvbSJdLCJpYXQiOjE0NTc0Njk4MDAsImV4cCI6MTQ1NzU1NjIwMH0.can9AMXZuw9NGF1a-qQBxC87q8j4ov7taa86HxIDo9g',
     transports: ['websocket']}
});

Alternatively, using an OAuth 2 token:

var socketio = io.connect(
    "https://spacesapis-socket.zang.io/chat",
    {query: 'tokenType=oauth&token=f746696f5de4528u128ae2f274eea253e8a7943a',
    transports: ['websocket']}
});

3 The Pub/Sub Model

Avaya Spaces uses a modified Publisher-Subscriber (Pub/Sub) model to manage messages. When a Socket.IO connection joins a particular Zang Space, it becomes both a publisher and subscriber to that space. It will be able to broadcast messages to others within the space, and will also receive messages from others broadcasting within the space. Upon leaving the space, it will no longer be able to do either. In a way, this closely mirrors the experience of a user sitting at a computer. They may have multiple Spaces open in different tabs, each of which can send and receive messages, but when they close a tab they won’t be able to send or receive messages anymore.

Note the critical distinction between users joining a Space and socket sessions joining a Space. Users can join or quit spaces through the Spaces GUI. When a socket session joins a Space, all it’s doing is establishing a socket connection with the Space for real time communications purposes.

4 Socket.IO Implementation

This Pub/Sub functionality is achieved by providing an additional layer of abstraction over Socket.IO. Avaya Spaces still uses the methods of Socket.IO, but adds authentication, authorization, and implements the model described above. Each Socket.IO room has a 1 to 1 correspondence to a Zang Space. To join a space, the socket session must send a SUBSCRIBE_CHANNEL event, specifying the id of the Space they wish to join. Sending messages is easily accomplished with the SEND_MESSAGE event. It’s important to note that the Space ID must still be specified in the SEND_MESSAGE event, as a socket session may have joined multiple spaces at the same time. To leave a space, the session simply broadcasts an UNSUBSCRIBE_CHANNEL event.