Does anyone know of any examples or pages that I can go to that implements a Live one on one chat using the CF10 Websockets? All the examples I found on the net were those of group chats where users subscribes to a certain channel. I need it so that there can be many instances of a one on one chat like how a Live Help Chat works that you see quite often on websites that allow you to chat with one of the support agents. Any help is appreciated and hopefully there will be examples (CF and JS).
-
Anyone have any idea? My initial thought was to create one chat channel and for every chat initiated by the client, I create that on a subchannel of chat like chat.chat1 or whatever. Then the agent side would connect to that channel so it would be like a one-on-one chat but I don't know if that's the correct way to do it. How are other people doing it? – Guest May 27 '13 at 17:26
-
Yeah I do, but I need to find some time to knock together some proof of concept code first. Gimme about 24h and I'll get back to you. – Adam Cameron May 27 '13 at 22:07
-
Great! Thanks! It's really hard to find a good example for this out there. – Guest May 28 '13 at 16:36
-
Yeah, I'm really surprised to find the same you did: basically all the chat demos out there are kinda... well... *wrong*: chats aren't broadcast. I'm working on a solution but I am out of time today, and can't return to it until Thursday, I'm afraid. – Adam Cameron May 28 '13 at 17:26
-
I've been trying to think of how the agent interface would work with websockets. Like once a user initiates a chat, how would an agent be notified on their end and initiate the chat to connect with that particular user? An example of this would be amazing. – Guest May 29 '13 at 21:58
-
Any luck with the example? Got it working with the broadcast method of generating a sub channel to chat with a random number when the user clicks the chat. On the admin side, currently they are subscribed to the parent chat channel so when a user opens a chat the notifications show up properly on the admin side and I am able to click on a link to connect with the user. The problem is, since the agent is connected to the parent chat, the user can't see the messages. If I try to subscribe to the sub channel it says I'm already subscribed since I'm subscribed to the parent. How do I get a 1 to 1? – Guest May 31 '13 at 21:13
3 Answers
Ben Nadel has a nice article about using CF10's websockets for pushing a message to a target user. He even added a nice demo video. This might be what you are looking for or could at least help you get started.

- 2,879
- 2
- 19
- 28
-
Thanks Jan! Looks really interesting and will read up on it. Just hope it will work in the Live Help Chat scenario where the user is just some random person connecting to the agent. – Guest May 28 '13 at 16:40
Here is some sample code that is currently working for me.
Instead of using the subscribeTo
attribute, use the js function to subscribe the user and pass in some header values. These headers can then be used as filters on the publish call 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>

- 11
- 2
At first I was thinking about implementing something similar but there are some rudimentary limitations in CF10 as of now that detours me from investigating further.
- WSS support is missing, see: Does CF10 support secure websocket wss?
- Websocket doesn't work in a cluster environment, see: https://groups.google.com/forum/#!topic/houcfug/M7YQQyrBTaQ
I would look elsewhere for any serious one-to-one live chat solution, maybe Socket.IO on NodeJS or Java
WSS may be coming in CF11. I'm not sure.