Subclass of MessageSource that allows to connect Messenger to another Messenger using it as external source.
var MessengerMessageSource = _.createSubclass(MessageSource, 'MessengerMessageSource');
module.exports = MessengerMessageSource;
_.extendProto(MessengerMessageSource, {
init: init,
addSourceSubscriber: addSourceSubscriber,
removeSourceSubscriber: removeSourceSubscriber,
postMessage: MessengerMessageSource$postMessage
});
Option name | Type | Description |
---|---|---|
sourceMessenger | Messenger | messenger this message source connects to |
Initializes MessengerMessageSource
Defines one parameter in addition to MessageSource parameters
function init(hostObject, proxyMethods, messengerAPI, sourceMessenger) {
MessageSource.prototype.init.apply(this, arguments);
this.sourceMessenger = sourceMessenger;
}
Option name | Type | Description |
---|---|---|
sourceMessage | String,Regex | source message to subscribe to |
Subscribes to source message. See MessageSource docs.
function addSourceSubscriber(sourceMessage) {
this.sourceMessenger.onSync(sourceMessage, { context: this, subscriber: this.dispatchMessage });
}
Option name | Type | Description |
---|---|---|
sourceMessage | String,Regex | source message to unsubscribe from |
Unsubscribes from source message. See MessageSource docs.
function removeSourceSubscriber(sourceMessage) {
this.sourceMessenger.off(sourceMessage, { context: this, subscriber: this.dispatchMessage });
}
Option name | Type | Description |
---|---|---|
message | String | |
data | Object |
Overrides defalut message source to dispatch messages synchronously
function MessengerMessageSource$postMessage(message, data) {
this.messenger.postMessageSync(message, data);
}