$channel = new \tool_realtime\channel($context, $component, $area, $itemid, $channeldetails);
$channel->notify($payload);
Subscribe in PHP before rendering the page:
$channel = new \tool_realtime\channel($context, $component, $area, $itemid, $channeldetails);
$channel->subscribe();
Listen in Javascript on the page:
import * as PubSub from 'core/pubsub';
import * as RealTimeEvents from 'tool_realtime/events';
PubSub.subscribe(RealTimeEvents.EVENT, (eventData) => {
if (eventData.component === 'mycomponent' && eventData.area === 'myarea') {
console.log('Received event', eventData);
}
});
Check if area is enabled in PHP:
if (\tool_realtime\manager::is_enabled($component, $area)) {
// ...
}