While preparing for my presentation earlier this week on WebSockets and ColdFusion 10, I ran into an issue trying to wrap my head around one of the features: invokeAndPublish. The docs describe it like so:
Invokes a specified method in a CFC file to generate the message that has to be published. Used in scenarios where you have raw data (that needs to be processed) to create a message.
First - I’ve got my Application.cfc that sets up my recognized WebSocket channels. If you didn’t attend my presentation, or haven’t read the docs yet, this is simply how we enumerate what channels are available to be used.
There are a few things in here I want you to ignore for right now so for now - let’s carry on. Next up is our front end. This is an incredibly simple chat type application. You enter text - it gets broadcast - and when messages come in they get printed to screen. That’s it.
You can demo this now here: http://fivetag-cf10beta.securecb1cf10.ezhostingserver.com/websocketmay11/
- The websocket channel.
- CFC name. This is dot notation and NOT a relative path. This is crucial! Remember in my Application.cfc where I made a root CF mapping? I did that because I have to use a mapping to refer to my CFC. So imagine I want to hit chat.cfc in the same folder. Instead of simply using "chat", which the docs seem to imply would work, I must use "root.chat".
- CFC method.
- Array of arguments for the CFC. Not a structure, but an array. You will want to ensure you nicely list out your arguments in the method. This is optional.