websocket

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2021 License: BSD-3-Clause Imports: 24 Imported by: 2

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\" }")
    

Documentation

Index

Constants

View Source
const WsStateURL = "/Services/websocket/State"

Variables

View Source
var (
	ErrInvalidLengthWebsocket        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowWebsocket          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupWebsocket = fmt.Errorf("proto: unexpected end of group")
)

Functions

This section is empty.

Types

type Action

type Action struct {
	Command   Command `json:"command"`
	EventType string  `json:"type"`
	Client    *Client
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

type Command

type Command uint8
const (
	SUBSCRIBE Command = iota
	UNSUBSCRIBE
)

type Config

type Config struct {
	Port                 int32    `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"`
	WriteWait            string   `protobuf:"bytes,3,opt,name=writeWait,proto3" json:"writeWait,omitempty"`
	PongWait             string   `protobuf:"bytes,4,opt,name=pongWait,proto3" json:"pongWait,omitempty"`
	PingPeriod           string   `protobuf:"bytes,5,opt,name=pingPeriod,proto3" json:"pingPeriod,omitempty"`
	MaxMessageSize       int64    `protobuf:"varint,6,opt,name=maxMessageSize,proto3" json:"maxMessageSize,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Config) Descriptor

func (*Config) Descriptor() ([]byte, []int)

func (*Config) GetMaxMessageSize

func (m *Config) GetMaxMessageSize() int64

func (*Config) GetPingPeriod

func (m *Config) GetPingPeriod() string

func (*Config) GetPongWait

func (m *Config) GetPongWait() string

func (*Config) GetPort

func (m *Config) GetPort() int32

func (*Config) GetWriteWait

func (m *Config) GetWriteWait() string

func (*Config) Marshal

func (m *Config) Marshal() (dAtA []byte, err error)

func (*Config) MarshalTo

func (m *Config) MarshalTo(dAtA []byte) (int, error)

func (*Config) MarshalToSizedBuffer

func (m *Config) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) Reset

func (m *Config) Reset()

func (*Config) Size

func (m *Config) Size() (n int)

func (*Config) String

func (m *Config) String() string

func (*Config) Unmarshal

func (m *Config) Unmarshal(dAtA []byte) error

func (*Config) XXX_DiscardUnknown

func (m *Config) XXX_DiscardUnknown()

func (*Config) XXX_Marshal

func (m *Config) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Config) XXX_Merge

func (m *Config) XXX_Merge(src proto.Message)

func (*Config) XXX_MessageName

func (*Config) XXX_MessageName() string

func (*Config) XXX_Size

func (m *Config) XXX_Size() int

func (*Config) XXX_Unmarshal

func (m *Config) XXX_Unmarshal(b []byte) error

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

type Payload

type Payload struct {
	Type   types.EventType `json:"type"`
	URL    string          `json:"url"`
	Data   string          `json:"data"`
	NodeId string          `json:"nodeid"`
	Value  string          `json:"value"`
}

func (*Payload) String

func (p *Payload) String() string

type WebSocket

type WebSocket struct {
	// contains filtered or unexported fields
}

func (*WebSocket) ConfigURL

func (w *WebSocket) ConfigURL() string

func (*WebSocket) Entry

func (w *WebSocket) Entry()

func (*WebSocket) Init

func (w *WebSocket) Init(api types.ModuleAPIClient)

func (*WebSocket) Name

func (w *WebSocket) Name() string

func (*WebSocket) NewConfig

func (w *WebSocket) NewConfig() proto.Message

func (*WebSocket) SetDiscoveryChan

func (w *WebSocket) SetDiscoveryChan(c chan<- types.Event)

func (*WebSocket) SetEventsChan

func (w *WebSocket) SetEventsChan(c <-chan types.Event)

SetEventsChan sets the event channel this is generally done by the API

func (*WebSocket) Stop

func (w *WebSocket) Stop()

func (*WebSocket) UpdateConfig

func (w *WebSocket) UpdateConfig(cfg proto.Message) (e error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL