Coldfusion 10 - Live One on One chat with Websockets
Asked Answered
F

3

7

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).

Feign answered 24/5, 2013 at 20:21 Comment(6)
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?Feign
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.Charades
Great! Thanks! It's really hard to find a good example for this out there.Feign
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.Charades
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.Feign
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?Feign
R
2

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.

Recrystallize answered 28/5, 2013 at 8:59 Comment(1)
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.Feign
T
1

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>
Tarn answered 4/12, 2013 at 18:33 Comment(0)
K
1

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.

  1. WSS support is missing, see: Does CF10 support secure websocket wss?
  2. 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.

Kassab answered 4/12, 2013 at 18:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.