How to use the lightning/empApi.subscribe function in lightning

To help you get started, we’ve selected a few lightning examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pozil / streaming-monitor / src / main / default / lwc / streamingMonitor / streamingMonitor.js View on Github external
const subscribePromises = channels.map(channel => {
            return subscribe(channel, replayId, streamingEvent => {
                this.handleStreamingEvent(streamingEvent);
            });
        });
        // Save susbcriptions and notify success once done
github pozil / streaming-monitor / src / main / default / lwc / streamingMonitor / streamingMonitor.js View on Github external
handleSubscribe(event) {
        const { channel, replayId } = event.detail;

        // Check for duplicate subscription
        if (this.subscriptions.some(sub => sub.channel === channel)) {
            this.notify(
                'error',
                'Cannot subscribe',
                `Already subscribed to channel ${channel}`
            );
            return;
        }

        subscribe(channel, replayId, streamingEvent => {
            this.handleStreamingEvent(streamingEvent);
        }).then(subscription => {
            this.notify(
                'success',
                'Successfully subscribed',
                subscription.channel
            );
            this.saveSubscription(subscription);
        });
    }