Constructor

CastMessageBus

new CastMessageBus(namespace, ipcChannel, senders, opt_messageType)

Parameter

namespace

string

The namespace for this message bus.

ipcChannel

cast.receiver.IpcChannel

The underlying message bus. for this channel.

Value must not be null.

senders

Array of string

The senders listening using this namespace.

Value must not be null.

opt_messageType

Optional

cast.receiver.CastMessageBus.MessageType

The type of messages sent/received by this CastMessageBus.

Value must not be null.

See also
cast.receiver.CastReceiverManager

Class

Enumerations

EventType

static

string

Events dispatched by cast.receiver.CastMessageBus.

Value

MESSAGE

Fired when there is a message.

SEND

Fired when there is a sendEvent.

MessageType

static

string

Message types used by cast.receiver.CastMessageBus.

Value

STRING

Messages are free-form strings. The application is responsible for encoding/decoding the information transmitted.

JSON

Messages are JSON-encoded. The underlying transport will use a JSON encoded string.

CUSTOM

Messages are CUSTOM-encoded. The application must implement its serializeMessage and deserializeMessage.

Properties

EventType

static

string

Events dispatched by cast.receiver.CastMessageBus.

Value

MESSAGE

Fired when there is a message.

SEND

Fired when there is a sendEvent.

MessageType

static

string

Message types used by cast.receiver.CastMessageBus.

Value

STRING

Messages are free-form strings. The application is responsible for encoding/decoding the information transmitted.

JSON

Messages are JSON-encoded. The underlying transport will use a JSON encoded string.

CUSTOM

Messages are CUSTOM-encoded. The application must implement its serializeMessage and deserializeMessage.

deserializeMessage

function(string) returns any type

Deserializes a serialized message. It can be overriden to provide a different type of deserialization.

Throws

Error If the deserialization does not match the message type.

onMessage

nullable function(non-null cast.receiver.CastMessageBus.Event)

Event handler for cast.receiver.CastMessageBus message event. This API is provided for convenience, applications can as well add event listeners to the CastMessageBus object ('message' event) as CastMessageBus is an EventTarget.

serializeMessage

function(non-null any type) returns string

Serializes a deserialized message. It can be overriden to provide a different type of serialization.

Throws

Error If the serialization does not match the message type.

Methods

broadcast

broadcast(message)

Sends a message to all the senders connected.

Parameter

message

any type

The message.

Value must not be null.

Throws

Error If there was an error preparing the message.

getCastChannel

getCastChannel(senderId) returns cast.receiver.CastChannel

Provides a cast.receiver.CastChannel for a specific senderId.

Parameter

senderId

string

The senderId.

Throws

Error If system is not ready or the sender is not connected.

Returns

non-null cast.receiver.CastChannel The CastChannel.

getMessageType

getMessageType() returns cast.receiver.CastMessageBus.MessageType

The type of messages processed by this CastMessageBus.

Returns

non-null cast.receiver.CastMessageBus.MessageType The CastMessageBus message Type.

getNamespace

getNamespace() returns string

The namespace of the messages processed by this CastMessageBus.

Returns

string The CastMessageBus namespace.

send

send(senderId, message)

Sends a message to a specific sender.

Parameter

senderId

string

The senderId.

message

any type

The message.

Value must not be null.

Throws

Error If there was an error preparing the message.