Includes the required JavaScript files in your CFM template and creates a global JavaScript reference to the WebSocket Object on the client-side.
<cfwebsocket name="" onMessage="">
cfwebsocket(name="", onMessage="");
false
this.wschannels
Application settings
cfwebsocket(name="ws", onMessage="handleMessage");
This example creates a JavaScript WebSocket object named ws
. When a message is pushed, the client runs the handleMessage
JavaScript function. This example also uses the subscribeTo
attribute so it will automatically subscribe to the channel chat
.
<cfwebsocket name="ws" onMessage="handleMessage" subscribeTo="chat" />
<script>
function handleMessage(message) {
// Output message object to console
console.log(message);
}
</script>
Sub-channels are created dynamically and are referenced by dot notation. When a message is broadcasted to a channel all its sub-channels receive the message as well. This only goes from top to bottom and not the other way around. In this example we create a JavaScript object called ws
and subscribe to the room-general
subchannel of the main chat
channel.
<cfwebsocket name="ws" onMessage="handleMessage" subscribeTo="chat.room-general" />
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.