HackDonalds' Emitter Socket
Table of Contents
Emitter socket is used to emit events in a socket client swarm.
Client: A WebSocket client on browser
Server: Websocket server
Room: A namespace Client connects to
Socket messages between Client and Server are always typeof RemoteTrigger
Install
Install with npm install @hackdonalds/emitter-socket
Import in your project:
import EmitterClient from "@hackdonalds/emitter-socket"
const EmitterClient = require("@hackdonalds/emitter-socket")
const peer = new EmitterClient({
host: 'localhost',
port: 8080,
room: 'room_name_to_connect_to'
})
To run emitter server
import {server} from "@hackdonalds/emitter/socket/dist/server"
const PORT = process.env.PORT || 8080
server.listen(PORT)
Examples
Trigger the event on every peer connected to the room:
peer.triggerOnRoom('event_type',{
...yourData
})
Or trigger event on another peer
peer.triggerOnClient(clientID, 'event_name', {
...yourData
})
API
...
License
MIT License © Hilmi Tolga SAHIN