This is packaging functions of browser websocket.
- node
var BrowserWebSocket = require('browser-websocket');
var ws = new BrowserWebSocket('ws://localhost:8000');
ws.on('open', function() {
ws.emit('hello world');
});
ws.on('message', function(e) {
var message = e.data;
console.log(message);
});
- html
<script src="browser-websocket.min.js"></script>
<script>
var ws = new BrowserWebSocket('ws://localhost:8000');
ws.on('open', function() {
ws.emit('hello world');
});
ws.on('message', function(e) {
var message = e.data;
console.log(message);
});
</script>
- node install
npm install browser-websocket --save
- use in html page
download "browser-websocket.min.js" (in dist folder)
<script src="browser-websocket.min.js"></script>
See /doc/bws.md
Released under the MIT license