<script src="/dlink-client/dlink.js"></script>
<script>
var socket = io('http://localhost');
socket.on('connect', function(){});
socket.on('event', function(data){});
socket.on('disconnect', function(){});
</script>
// with ES6 import
import io from 'dlink-client';
const socket = io('http://localhost');
A slim build (without JSON3
, a JSON polyfill for IE6/IE7, and debug
) is also available: dlink.slim.js
.
Add dlink-client
to your package.json
and then:
var socket = require('dlink-client')('http://localhost:8080/namespace1');
socket.on('connect', function () {
socket.subscribe('room1', msg => {
console.log(msg);
});
socket.publish('room1', 'hello world');
});
socket.on('disconnect', function () {
console.log('disconnect');
});
See API