Create a connection to exchange data between Ghosts.
- WebSockets don't receive commands therefore use an HTTP client if you need to proceed with commands.
import hiveWS from '@norniras/hive-agent/ws'
Create an instance of HiveWS
const hiveWS = createHiveWS({
type: 'string',
token: 'yours_token',
rootDomain: 'example.com',
ghostAddress: 'domain/service/ghostID',
})
This method will open a ws connection.
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)
When string connection is opened you can send messages to ghostAddress.
hiveWS.open()
This method will send data to the Hive.
hiveWS.sendData(data) // data is an object - keys should meet service data structure
This method will close a ws connection.
hiveWS.close()