cfwebsocket
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="");
Attribute Reference
name string Required
onMessage string Required
onOpen string
onClose string
onError string
usecfAuth boolean
Default: false
false
subscribeTo string
this.wschannels Application settings secure boolean
Compatibility
ColdFusion:
Links more information about cfwebsocket
- - Slides and Code from the "Realtime with Websockets" presentation at ColdFusion Summit 2014 & 2015. Includes AdvancedSocket which aims to help handling connectivity issues from the client side when using ColdFusion WebSocket solution. As well as a drop in test suite within the console folder which was re-skinned and updated from Adobe's original example.
- HTML5 WebSockets and ColdFusion by Awdhesh Kumar - Original post from 2012 by Awdhesh Kumar regarding using WebSockets in ColdFusion 10.
- Using WebSocket with ColdFusion 11 by Awdhesh Kumar - Follow up post by Awdhesh Kumar in 2014 regarding enhancements to WebSockets in ColdFusion 11.
- Using WebSocket to broadcast messages - Adobe - Examples available on ColdFusion documentation
Examples Sample code using the cfwebsocket tag
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" />
© 2012–present Foundeo, Inc. and the CFDocs contributors.
Licensed under the MIT License.
ColdFusion is a trademark of Adobe Systems Incorporated.
https://cfdocs.org/cfwebsocket