UI layer. Handles sending and receiving messages from the WebSocket connections.
The Message format is reused for WebSocket specific messages (WebSocketErrorMessage, WebSocketIdMessage) and application-specific messages (ClientMessage)
The WebSocketHandler consists of four main components:
The WebSocket session IDs, are reused for the user's session ID. The ID is assumed to be unique.
When connected to the WebSocket, an implementation can send or receive the following messages (as JSON objects).
ClientMessage
. Send a black box signaling message to another peer.
type
: The message type. Has to be defined by the developer. E.g. "SignalingMessage" for WebRTC signaling messages or "CustomMessage" for custom messages.recipientSessionId: String
. The recipient's session ID. Used for routing.messageBody: String
. The free-form message body. To the transport layer, this is a black box. May therefore include stringified JSON.Example:
{
"type": "CustomMessage",
"recipientSessionId": "ABCDEF",
"messageBody": "Hi ABCDEF!"
}
All these incoming message types have to be handled. They are distinguishable by their type
field. They are sent as JSON objects.
``
WebSocketIdMessage
. Includes the session ID.
type: String
. Static value WebSocketIdMessage
id: String
. The session IDWebSocketErrorMessage
. Tells the implementation that something went wrong
type: String
. Static value WebSocketErrorMessage
error: String
. The error messageClientMessage
. Incoming, application-defined messages
type: String
. The message type as defined by the developer (see above)senderSessionId: String
. The sender' session ID. Can be used to reply to messagesrecipientSessionId: String
. The recipient's session ID. This should be the current session ID!messageBody: String
. The free-form message body
data class WebSocketErrorMessage : Message
Error messages meant for the WebSocket |
|
class WebSocketHandler
Main handler class |
|
data class WebSocketIdMessage : Message
New ID message |
const val IDLE_TIMEOUT_MS: Long
WebSocket session idle timeout in milliseconds. |
|
const val WEBSOCKET_PATH: String
Path that the WebSocket handler is available on |
|
const val WEB_SUB_PATH: String
Sub path (to the resources directory) of the web site |
fun main(args: Array<String>): Unit
Main start point. Fires up the Webserver. |