package
0.2.0
Repository: https://github.com/kraken-hpc/kraken.git
Documentation: pkg.go.dev

# README

Websocket Module

The websocket module allows for a client to subscribe to a stream of kraken events. Currently the Module supports subscribing to these events:

  • STATE_CHANGE
  • STATE_MUTATION
  • DISCOVERY

How to use websocket with Kraken

These steps are assuming that Kraken is running and is built with the websocket module. It also assumes that both the restapi module and websocket module are in RUN state.

  1. Retrieve the websocket information from the restapi by making a GET request to http://{RESTAPI_IP}:{RESTAPI_PORT}/ws

    • This will return an object of this schema:
      {
        "websocket": {
          "host": "{WEBSOCKET_IP}", 
          "port": "{WEBSOCKET_PORT}",
          "url": "{WEBSOCKET_URL}"
        }
      }
      
  2. You can now open a websocket with the information provided. Here's an example in javascript with fetch and WebSocket:

    fetch("http://{RESTAPI_IP}:{RESTAPI_PORT}/ws")
      .then(resp => resp.json())
      .then(json => {
        const wsurl = `ws://${json.websocket.host}:${json.websocket.port}${json.websocket.url}`
        websocket = new WebSocket(wsurl)
    
  3. Once a websocket connection is established you can send a subscription request to subscribe to an event stream. Here's another javascript example:

    this.websocket.send("{ \"command\": \"SUBSCRIBE\", \"type\": \"STATE_CHANGE\" }")
    this.websocket.send("{ \"command\": \"SUBSCRIBE\", \"type\": \"STATE_MUTATION\" }")
    this.websocket.send("{ \"command\": \"SUBSCRIBE\", \"type\": \"DISCOVERY\" }")
    

# Constants

No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author