event-broadcast: A dumified WebSocket wrapper
IE / Edge
Why did we build event-broadcast?
- Our goal is to make the learning curve to create websockets and real time applications lower.
Why use event-broadcast?
- No server needed to get started.
- Free (Paid tier possible in the future)
- Get started in a few lines of code: Seriously, copy the following code and put it in the
<body>of you html then open your html multiple times and see them communicate with each other immediately.
In the browser:
This may feel like a bunch of magic but, if you put the codes above to any of your pages, those pages will start communicating with each other.
In a NodeJs server:
var Ca$t = ;var chat = '';chat;
The constructor that initialize the connection. The
domain parameter is not required. The library will try to automatically detect your domain or host name. It is recommended to provide your domain name to make sure your applications (website or servers) are in the same channel and ablet to communicate with each other.
(String) Not required
The string that will identify your application's channel (Usually your app's domain). All apps that share the same domain will be in the same channel, this includes webapps, mobile apps and node servers.
let mainChannel = '';
Creates and fires an event along with a payload if provided.
The event identifier that will be emitted/fired. This must match the event listener.
(JSON) Not required
The data that will be broadcasted to everyone.
Ca$t.on('event-name', callBack(data)): Listens to an event then fires
The event identifier that the event listener will listen to. This must match the exact event name.
(callable function) Required
The function that will be executed once the event is fired. If the event is fired with a payload, the callback will receive a parameter conatining the data.
Built in events:
close: Fired when connection is closed or disconnected.
error: Fired when an error occur.
onmessage: Fired when a new message is received.
connect: Fired on successfull connection.