Skip to content

Latest commit

 

History

History
66 lines (44 loc) · 1.12 KB

README.md

File metadata and controls

66 lines (44 loc) · 1.12 KB

Hive WebSocket

Create a connection to exchange data between Ghosts.

Note

  • WebSockets don't receive commands therefore use an HTTP client if you need to proceed with commands.

Import

import hiveWS from '@norniras/hive-agent/ws'

How to use

Create an instance of HiveWS

const hiveWS = createHiveWS({
  type: 'string',
  token: 'yours_token',
  rootDomain: 'example.com',
  ghostAddress: 'domain/service/ghostID',
})

WebSocket Open

This method will open a ws connection.

Channel Example

When channel connection is opened you can receive messages from ghostAddress.

const dataHandler = data => {
  // do something with the data
  console.log(data)
}
hiveWS.open(dataHandler)

String Example

When string connection is opened you can send messages to ghostAddress.

hiveWS.open()

WebSocket SendData

This method will send data to the Hive.

hiveWS.sendData(data) // data is an object - keys should meet service data structure

WebSocket Close

This method will close a ws connection.

hiveWS.close()