engine.io-browser
v4.0.0
Published
Client for the realtime Engine
Downloads
2
Readme
Engine.IO browser
This is the browser-only client for Engine.IO, the implementation of transport-based cross-browser/cross-device bi-directional communication layer for Socket.IO.
How to use
Standalone
You can find an engine.io.js
file in this repository, which is a
standalone build you can use as follows:
<script src="/path/to/engine.io.js"></script>
<script>
// eio = Socket
const socket = eio("ws://localhost");
socket.on("open", () => {
socket.on("message", (data) => {});
socket.on("close", () => {});
});
</script>
With browserify
Engine.IO is a commonjs module, which means you can include it by using
require
on the browser and package using browserify:
install the package
$ npm install engine.io-browser
write your app code
const socket = require("engine.io-browser")("ws://localhost"); socket.on("open", () => { socket.on("message", (data) => {}); socket.on("close", () => {}); });
build your app bundle
$ browserify app.js > bundle.js
include on your page
<script src="/path/to/bundle.js"></script>
Sending and receiving binary
<script src="/path/to/engine.io.js"></script>
<script>
const socket = new eio.Socket("ws://localhost/");
socket.binaryType = "blob";
socket.on("open", () => {
socket.send(new Int8Array(5));
socket.on("message", (blob) => {});
socket.on("close", () => {});
});
</script>