Client Presence

Realtime detection of user state on channels, please contact GoEasy to enable this function.

Initialize GoEasy

    var goEasy = new GoEasy({
        host:'hangzhou.goeasy.io',//your application region: [hangzhou.goeasy.io |singapore.goeasy.io]
        appkey: "my_appkey",
        userId: "user unique id", //required, client presence function based on this
        userData: "user extra data" //optional
    });

Receive client presence message

There are four actions for this feature:
online: User reconnects to GoEasy again because of network unstable.
offline: User closes the client or losts network connection.
join: User first subscribe the channel.
leave: User unsubscribe the channel.

    goEasy.subscribePresence({
        channel: "my_channel",
        onPresence: function(presenceEvents){
            console.log("Presence events: ", JSON.stringify(presenceEvents));
        }        
    });

Stop receiving client presence message

    goEasy.unsubscribePresence({
        channel: "my_channel"
    });

Get current online clients

JavaScript

    goEasy.hereNow({
        channels: ["my_channel", "my_channel2"],
        includeUsers: true, //optional, default only return online amount, if set true, user list will be included
        distinct: true //optional, if the includeUsers set to be true, and just keep one user with same userId, set it true
    },function(response) {
        alert("hereNow response: " + response);           
        /**
        response example:
        {
           "code": 200,
           "content": {
              "channels": {
                 "channel_A": {     
                    "channel": "channel_A",
                    "clientAmount": 2,    
                    "userAmount": 2,     
                    "users": [    
                       {"id":"Jack","data":"18 years old"}, 
                       {"id":"Ted","data":""}                                    
                    ]
                 },
                 "channel_B": {
                    "channel": "channel_B",
                    "clientAmount": 1,     
                    "userAmount": 1,       
                    "users": [     
                       {"id":"Tom","data":"18 years old"}
                    ]
                 }
              }
           }
        }
        **/
    });

Rest API

    Request: 
        URL: http(s)://<Rest Host>/herenow?appkey={appkey}&channel={channel}&includeUsers={includeUsers}&distinct={distinct}
        Method: GET
        Parameters:
        channel         //required
        includeUsers    //optional, default only return online amount, if set true, user list will be included
        distinct        //optional, if the includeUsers set to be true, and just keep one user with same userId, set it true 

    Response JSON:
        //response example    
        {
           "code": 200,
           "content": {
              "channels": {
                 "channel_A": {   
                    "channel": "channel_A",
                    "clientAmount": 3,
                    "userAmount": 2, 
                    "users": [    
                       {"id":"Jack2","data":"18 years old"}, 
                       {"id":"Ted2","data":""}
                    ]
                 },
                 "channel_B": {      
                    "channel": "channel_B",
                    "clientAmount": 1,     
                    "userAmount": 1, 
                    "users": [     
                       {"id":"Tom","data":"18 years old"},  
                    ]
                 }
              }
           }
        }

results matching ""

    No results matching ""