Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### METHOD(S)
- To `Signal a message` you can use the following method(s) in the Java V4 SDK:
- ```java
- this.pubnub.signal().message(Object).channel(String);
- ```
- | Parameter | Type | Required | Description |
- | --------- | ---------- | -------- | ----------- |
- | `message` | `Object` | Yes | The payload which will be serialized and sent. |
- | `channel` | `String` | Yes | The channel which the signal will be sent to. |
- | `sync` | `PNPublishResult` | No | Executes the call. Blocks the thread, exception is thrown if something goes wrong. |
- | `async` | `PNCallback<PNPublishResult>` | No | Executes the call asynchronously. |
- ### BASIC USAGE
- #### SIGNAL A MESSAGE TO A CHANNEL:
- ```java
- pubnub.signal()
- .message("Hello everyone!")
- .channel("bar")
- .async(new PNCallback<PNPublishResult>() {
- @Override
- public void onResponse(PNPublishResult pnPublishResult, PNStatus pnStatus) {
- if (pnStatus.isError()) {
- Long timetoken = pnPublishResult.getTimetoken(); // signal message timetoken
- } else {
- pnStatus.getErrorData().getThrowable().printStackTrace();
- }
- }
- });
- ```
- ### RESPONSE
- The `signal()` operation returns a `PNPublishResult` object which contains the following operations:
- | Method | Type | Description |
- | ---------------- | ---------- | ------------ |
- | `getTimetoken()` | Long | Returns a long representation of the time token when the signal was published.|
- ### LISTENER
- Signals arrive at the `signal()` method inside the PubNub's `SubscribeCallback` listener.
- ```java
- pubnub.addListener(new SubscribeCallback() {
- // other callbacks omitted
- @Override
- public void signal(PubNub pubnub, PNSignalResult pnSignalResult) {
- System.out.println("Signal publisher: " + signal.getPublisher());
- System.out.println("Signal payload: " + signal.getMessage());
- System.out.println("Signal subscription: " + signal.getSubscription());
- System.out.println("Signal channel: " + signal.getChannel());
- System.out.println("Signal timetoken: " + signal.getTimetoken());
- }
- });
- ```
- ## SUBSCRIBE RETURNS
- The `subscribe()` operation returns a `PNSignalResult` for signals which contains the following operations:
- | Method | Type | Description |
- | ------------------- | ----------------- | ----------------- |
- | `getMessage()` | `JsonElement` | The signal sent on the channel. |
- | `getSubscription()` | `String` | The channel group or wildcard subscription match (if exists). |
- | `getChannel()` | `String` | The channel for which the signal belongs. |
- | `getTimetoken()` | `Long` | Timetoken for the signal. |
- | `getUserMetadata()` | `Object` | User metadata. |
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement