BX.PULL.subscribe
Description and parameters
BX.PULL.subscribe - JS method.
Subscription to Push&Pull module events. There are three formats for subscriptions, you can select a suitable format depending on your tasks.
Parameters
Parameter | Description |
---|---|
type | Subscription type (
Server, Client, Online
Stand for constants:
BX.PullClient.SubscriptionType.Server, BX.PullClient.SubscriptionType.Client, BX.PullClient.SubscriptionType.Online ) - may be skipped, Server type is set by default. |
moduleId | Module that sent the command. |
command | Command initializing the subscription |
callback | Handler function |
Examples of use
Subscription for all module events.
BX.PULL.subscribe({ moduleId: 'exampleModule', callback: function (data) { if (command == 'exampleCommandOne') { doSomething(); } else if (command == 'exampleCommandTwo') { doSomething2(); } }.bind(this) });
Subscription to a single command
BX.PULL.subscribe({ type: BX.PullClient.SubscriptionType.Server, moduleId: 'im', command: 'messageChat', callback: function (params, extra, command) { console.warn('Receive message:', params.message.text) }.bind(this) });
Subscription to multiple commands using router function
BX.PULL.subscribe({ type: BX.PullClient.SubscriptionType.Server, moduleId: 'im', callback: function (data) { if (data.command == 'messageAdd') { this.doSomething(); } }.bind(this) });
Subscription using router class
BX.PULL.subscribe(new CommandHandler(options));
© «Bitrix24», 2001-2024