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?– GuestMay 27, 2013 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 CameronMay 27, 2013 at 22:07
-
Great! Thanks! It's really hard to find a good example for this out there.– GuestMay 28, 2013 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 CameronMay 28, 2013 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.– GuestMay 29, 2013 at 21:58
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.
-
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.– GuestMay 28, 2013 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>
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.