All the data that is published in your channel passes through your Channel Listener CFC. In this blog post I will explain the various Channel Listener functions that are called when a data is published.
A Channel Listener CFC is associated with a channel. All the sub-channels of that channel also will be controlled by the same Channel Listener CFC.To see sample code on how to associate a channel with a Channel Listener CFC check my previous blog entry
Consider a scenarios where you have four clients C1 , C2, C3 and C4.
Consider a case where News is the main channel. Sports and Politics are sub-channels of News. Tennis is a sub-channel of sports.C1 is subscribed to News
C2 is subscribed to News.Sports
C3 is subscribed to News.Sports.Tennis
C4 is subscribed to News.Politics .
Whenever data has to be published over the channel, four Channel Listener functions are called internally.
- AllowPublish - Verifies if the publisher has the right to publish. If this function returns true, the message is eligible to be published.
- BeforePublish - This method can be used to format the message.
- CanSendMessage - This method is executed for each client. This function validates if each of the clients is eligible to receive the message.
- BeforeSendMessage -This method is executed for each client. This method can be used to format the message differently for each client.
See the following diagram which shows the flow of data as well as the order of function calls during a data publish.
The above diagram also explains how different clients receive data.
For example C2 - subscribed to News sports will receive any data that comes on News.Sports and its sub-channels(In this case News.Sports.Tennis).
C2 will not receive data on any sibling channel(News.Politics) or parent channel(News).
Also you can see that C1 subscribed to News will receive data on all channels.
For more reference and code samples on ColdFusion WebSocket see the previous entries in this ColdFusion WebSocket blog series
- ColdFusion WebSocket Part1:Getting Started
- ColdFusion WebSocket Part2:How do I publish Messages?
- ColdFusion WebSocket Part3: Interpreting response
- ColdFusion WebSocket Part4:Restricting Right to Publish