Unread messages

Receive unread message

When the user goes online again, he could get lost messages during his offline time.
Offline:User closes all clients on the channel.
Online:Use opens the client and subscribe the channel.

How to enable unread messages function

The userId is required when 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"
    });

Example:

Prepare two html pages.

goeasy_receive.html
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <title>GoEasy receive</title>
        <script type="text/javascript" src="http://cdn.goeasy.io/goeasy-1.0.0.js"></script>
        <script type="text/javascript">
            var goEasy = new GoEasy({
                host: "hangzhou.goeasy.io",//your application region:[hangzhou.goeasy.io | singapore.goeasy.io] 
                appkey: "my_appkey", 
                userId: "user unique id" 
            });
            goEasy.subscribe({
                channel: "my_channel",
                onSuccess: function () {
                    console.log("Subscribe successfully.");
                },
                onFailed: function (error) {
                    console.log("Subscribed failed: "+error.content);
                },onMessage: function (message) {
                    console.log("Channel:" + message.channel + " content:" + message.content);
                }
            });
        </script>
    </head>
    <body>
        <div id="tip">Please open browser console, see the log details.</div>
    </body>
    </html>

goeasy_publish.html
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <title>GoEasy publish</title>
        <script type="text/javascript" src="http://cdn.goeasy.io/goeasy-1.0.0.js"></script>
        <script type="text/javascript">
            var goEasy = new GoEasy({
                host: "hangzhou.goeasy.io",your application region:[hangzhou.goeasy.io | singapore.goeasy.io]
                appkey: "my_appkey" 
            });
            function publish() {
                var message = document.getElementById("messageContent").value;
                goEasy.publish({
                    channel: "my_channel",
                    message: message,
                    onSuccess: function () {
                        console.log("Subscribe successfully.");
                    },
                    onFailed: function (error) {
                        console.log("Subscribed failed: "+error.content);
                    }
                });
            }
        </script>
    </head>
    <body>
        <textarea id="messageContent" rows="5" cols="50"></textarea>
        <button type="button" onclick="publish();">Publish</button>
    </body>
    </html>

Operation steps:

  1. Open two html pages: host, appkey, userId
  2. Open goeasy_receive.html
  3. Open goeasy_publish.html, click 'Publish' button and to see received message in goeasy_receive.html
  4. Close goeasy_receive.html, so that the user is offline, and then publish messages on goeasy_publish.html
  5. Reopen goeasy_receive.html, the user is online and he will receive the message sent just now

results matching ""

    No results matching ""