Here is a sample code that currently works for me.
Instead of using the subscribeTo attribute, use the js function to subscribe to the user and pass some header values. These headers can then be used as filters when invoking a publication using selector
Example:
<cfwebsocket name="ChatSocket" onOpen="openHandler" onMessage="msgHandler" onError="errHandler"> <script> function openHandler(){ //Subscribe to the channel, pass in headers for filtering later ChatSocket.subscribe('chatChannel',{name: '#Session.Auth.FirstName#', UserID: '#Session.Auth.UserID#', AccountID: '#Session.Auth.AccountID#' }); } function publish(txt, userID){ var msg = { AccountID: "#Session.Auth.AccountID#", publisher: '#Session.Auth.UserID#', id: userID, message: converthtml(txt) }; //When including headers, the "selector" is where you will filter who it goes to. var headers = { AccountID: "#Session.Auth.AccountID#", publisher: '#Session.Auth.UserID#', id: userID, selector: "UserID eq '"+userID+"' and AccountID eq '#Session.Auth.AccountID#'" }; ChatSocket.publish('chatChannel',msg, headers); } function msgHandler(message){ console.log(message); } function errHandler(err){ console.log(err); } </script>
Sean B.
source share