import MessageBuilderService from 'netflux/src/service/MessageBuilderService.js'
MessageBuilderService
Extends:
Message builder service is responsible to build messages to send them over the
WebChannel
and treat messages received by the WebChannel
. It also manage
big messages (more then 16ko) sent by users. Internal messages are always less
16ko.
Method Summary
Public Methods | ||
public |
handleUserMessage(data: UserMessage, senderId: number, recipientId: number, action: function(dataChunk: ArrayBuffer), isBroadcast: boolean) Prepare user message to be sent over the |
|
public |
Build a message which can be then sent trough the |
|
public |
readHeader(data: ArrayBuffer): MessageHeader Extract header from the message. |
|
public |
readInternalMessage(data: ArrayBuffer): Object Read internal Netflux message. |
|
public |
readUserMessage(wc: WebChannel, senderId: number, data: ArrayBuffer, action: function(msg: UserMessage, isBroadcast: boolean)) Read user message which was prepared by another peer with MessageBuilderService#handleUserMessage and sent. |
Public Methods
public handleUserMessage(data: UserMessage, senderId: number, recipientId: number, action: function(dataChunk: ArrayBuffer), isBroadcast: boolean) source
Prepare user message to be sent over the WebChannel
.
Params:
Name | Type | Attribute | Description |
data | UserMessage | Message to be sent |
|
senderId | number | Id of the peer who sends this message |
|
recipientId | number | Id of the recipient peer |
|
action | function(dataChunk: ArrayBuffer) | Send callback executed for each data chunk if the message is too big |
|
isBroadcast | boolean |
|
Equals to true if this message would be
sent to all |
public msg(code: number, senderId: number, recepientId: number, data: Object): ArrayBuffer source
Build a message which can be then sent trough the Channel
.
public readHeader(data: ArrayBuffer): MessageHeader source
Extract header from the message. Each user message has a header which is a part of the message metadata.
Params:
Name | Type | Attribute | Description |
data | ArrayBuffer | Whole message |
public readInternalMessage(data: ArrayBuffer): Object source
Read internal Netflux message.
Params:
Name | Type | Attribute | Description |
data | ArrayBuffer | Message |
public readUserMessage(wc: WebChannel, senderId: number, data: ArrayBuffer, action: function(msg: UserMessage, isBroadcast: boolean)) source
Read user message which was prepared by another peer with MessageBuilderService#handleUserMessage and sent.
Params:
Name | Type | Attribute | Description |
wc | WebChannel | WebChannel |
|
senderId | number | Id of the peer who sent this message |
|
data | ArrayBuffer | Message |
|
action | function(msg: UserMessage, isBroadcast: boolean) | Callback when the message is ready |