WebSockets

Interacting with web socket servers from Blueprint

You can connect to your web socket server to send/receive JSON messages from blueprint.

This feature is only available in V25 onwards

Usage Overview

To use the web socket connection, create a new instance of the M2 Web Socket Connection class and store it somewhere in a Blueprint graph.

Authentication

Optionally, call Set Actor Auth Context / Set Actor Component Auth Context passing the Morpheus Actor or Morpheus Actor Component you ant to use as the basis for your authentication.

If you opt to include the delegated auth token, then the initial web socket connection will include an auth token used to help you validate the user's M2 Identity.

As part of authentication you can select one of the M2 Web Platform scopes. If you do so, the following additional headers are added to the request:

When connecting to your web socket server, the auth header will be passed in the initial http request headers as an Authorization: Bearer header.

Connecting

To connect to the Web Socket server you call the Connect method on the connection class.

The parameters are as follows:

Sending Messages

Once your web socket is connected you can send messages via SendJson. This will take a JsonObject and send it to your remote server as a serialized string.

Handling Disconnection

Disconnection can be manually requested by calling the Disconnect event. This will send a default status of 1000 and no reason string.

Your web socket server connection may be disconnected for other means, such as network errors between the client and web socket server, problems in the web socket server or just that the connection is set to time out.

You can call Reconnect to connect to a web socket that has moved into the disconnected state; however you must have called Connect on it beforehand.

Due to the custom nature of many web socket services, we do not provide automatic reconnection logic. You must manage this yourself by calling Reconnect if required.

Last updated