Wrapper of ws and WebSocket.
It uses:
- ws on Node
- global.WebSocket in browsers
Before using this module you should know that
ws
is not perfectly API compatible with
WebSocket,
you should always test your code against both Node and browsers.
Some major differences:
- no
Server
implementation in browsers
You need to install both this package and ws:
> npm i kk-websocket ws
Then just require this package:
const WebSocket = require('kk-websocket')
const ws = new WebSocket('wss://echo.websocket.org/', {
origin: 'https://websocket.org'
});
ws.on('open', function open() {
console.log('connected');
ws.send(Date.now());
});
ws.on('close', function close() {
console.log('disconnected');
});
ws.on('message', function incoming(data) {
console.log(`Roundtrip time: ${Date.now() - data} ms`);
setTimeout(function timeout() {
ws.send(Date.now());
}, 500);
});
.travis.yml
- Travis CI> npm run coveralls
package.json
- NPM- prepublishOnly
> nps test clean build
- coveralls
> nps coveralls # nps coverage && nyc report --reporter=text-lcov | coveralls
- coverage
> nps coverage # nyc ./node_modules/mocha/bin/_mocha
- test
> nps test
- start
> nps
- prepublishOnly
package-scripts.js
- NPS- build
- lint
- clean
- test
- node
- browser
- bundle
- coverage
- coveralls
- prebuildDocs
- buildDocs
- postbuildDocs
- prewatchDocs
- watchDocs
karma.conf.js
(Karma)