Skip to content

Latest commit

 

History

History
109 lines (89 loc) · 2.96 KB

websocket.md

File metadata and controls

109 lines (89 loc) · 2.96 KB
title keywords last_updated sidebar permalink folder
Receiving WebSocket Events
sdk, web socket
mydoc_sidebar
/essentials/sdk/websocket
essentials/sdk

Receiving WebSocket Events

Realtime event triggering is trending in modern application development. It helps application to always be up to date and so provides better user experiences. Bitmark SDK offers Web Socket event triggering so that the application can be notified immediately when anything changes.

Event

  • New block: Sent when the Bitmark blockchain has a new block.
    • blockNumber : new block number
  • Bitmark changed: Sent when users issue new bitmarks, receive new bitmarks, or send them to a new owner.
    • bitmarkId: the id of the bitmark that changed
    • txId: the corresponding transaction id
    • presence: whether the bitmark is owned or not by the corresponding Account
  • New transfer offer: Sent when users receive new transfer offers, for two-signatures transfer.
    • bitmarkId: the id of the bitmark that's offered.
  • New pending issuance: Sent when users issue new bitmarks.
    • bitmarkId : the id of the bitmark that's issuing.
  • New pending transfer: Sent when a transfer occurs, to both sender and receiver.
    • txId: the transaction id
    • owner: the recipient of this transfer
    • prevTxId: the previous transaction id
    • prevOwner: the sender who made the transfer

Note: The attribute names could be different depending on the SDK used. This document refers specifically to the Java SDK.

Connect/Disconnect

{% codetabs %} {% codetab Java %}

WebSocket.ConnectionEvent connEvent = new WebSocket.ConnectionEvent() {
            @Override
            public void onConnected() {

            }

            @Override
            public void onDisconnected() {

            }

            @Override
            public void onConnectionError(Throwable e) {

            }
        }
BitmarkWebSocket ws = new BitmarkWebSocketService();

// connect
ws.connect(authKeyPair);

// disconnect
ws.disconnect();

{% endcodetab %} {% codetab Swift %}

// TODO

{% endcodetab %} {% endcodetabs %}

Subscribe/Unsubscribe

{% codetabs %} {% codetab Java %}

// subscribe
ws.subscribeBitmarkChanged(
                address,
                new BitmarkWebSocket.BitmarkChangedEvent() {

                    @Override
                    public void onChanged(
                            String bitmarkId,
                            String txId,
                            boolean presence
                    ) {

                    }

                    @Override
                    public void onSubscribeSuccess(SubscribeSuccessEvent event) {

                    }

                    @Override
                    public void onSubscribeError(SubscribeErrorEvent event) {

                    }
                }
        );

// unsubscribe
ws.unsubscribeBitmarkChanged(address);

{% endcodetab %} {% codetab Swift %}

// TODO

{% endcodetab %} {% endcodetabs %}