io

Returns a fluent emitter for a WebSocket channel — sugar over the same registry the wsPublish built-in uses. The channel argument is optional inside a channel handler, where io() with no argument refers to the current channel. The emitter supports emitting to the whole channel, to a specific room, excluding a connection, counting members, listing connection ids, and reading the presence roster. Only available in serve mode, where a live registry is present.

io( [ channel ] ) → returns any

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

channel string

The channel to emit on, e.g. "/chat". Inside a channel handler this defaults to the current channel.

Links more information about io

Examples
Sample code invoking the io function

The fluent emitter scopes fan-out with to(), excepts a connection with except(), and inspects the channel with count(), sockets(), and presence().

io( "/chat" ).emit( "ping", now() );
io( "/chat" ).to( "lobby" ).emit( "announcement", { text = "hello" } );
io( "/chat" ).to( "lobby" ).except( cid ).emit( "x", data );

var members = io( "/chat" ).in( "lobby" ).count();
var ids     = io( "/chat" ).sockets();
var roster  = io( "/chat" ).presence();

Inside a handler, io() with no argument refers to the current channel.

component socket="/chat" encoding="json" {
    function onMessage( socket, message ) {
        io().to( "lobby" ).emit( "message", { from = socket.id(), text = message.text } );
    }
}

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub