Listeners and Events handling

Network Status

When initial the GoEasy Object, you could register related events to listening the network status. For detailed error status, please read the Appendix A according to the error code.

JavaScript

    var goEasy = new GoEasy({
        appkey: "my_appkey",
        onConnected: function () {
            alert("Connect to GoEasy success.");
        },
        onDisconnected: function () {
            alert("Disconnect to GoEasy server.")
        },
        onConnectFailed: function (error) {
            alert("Connect to GoEasy failed, Error code: "+error.code+" Error message: "+error.content);
        }
    });

Publish message

When you publish a message, you could register a listener to listen the status of this message. For detailed error status, please read the Appendix A according to the error code.

Java

    goEasy.publish("my_channel","Hello, GoEasy!", new PublishListener(){
        @Override
        public void onSuccess() {
            System.out.print("Publish message success.");
        }
        @Override
        public void onFailed(GoEasyError error) {
            System.out.print("Publish message failed, Error code:" + error.getCode() + " Error message: " + error.getContent());
        }
    });

JavaScript

    goEasy.publish({
        channel: "my_channel",
        message: "Hello GoEasy!",
        onSuccess:function(){
            alert("Publish message success.");
        },
        onFailed: function (error) {
            alert("Publish message failed, Error code:"+error.code+" Error message:"+error.content);
        }
    });

Receive message(Subscribe Channel)

When you subscribe a channel, you could register a listener to monitor the subscription related status. For detailed error status, please read the Appendix A according to the error code.

JavaScript

    goEasy.subscribe({
        channel: "my_channel",
        onMessage: function (message) {
            alert("You have new message:channel:" + message.channel + " Content: " + message.content);
        },
        onSuccess: function () {
            alert("Subscribe the Channel successfully.");
        },
        onFailed: function (error) {
            alert("Subscribe the Channel failed, error code:" + error.code + " error message: " + error.content);
        }
    });

Cancel Subscribed Channel

When you cancel a subscription of a channel, you will stop to receive message from this channel at once. You also could register a listener to monitor the cancel subscription events. For detailed error status, please read the Appendix A according to the error code.

JavaScript

    goEasy.unsubscribe({
        channel: "my_channel",
        onSuccess: function () {
            alert("Cancel Subscription successfully.");
        },
        onFailed: function (error) {
            alert("Cancel the subscription failed, error code:" + error.code + " error message: " + error.content);
        }
    });

results matching ""

    No results matching ""