w-websocket-client
v1.0.29
Published
A wrapper for websocket in nodejs and browser.
Downloads
106
Maintainers
Readme
w-websocket-client
A wrapper for websocket in nodejs and browser.
Documentation
To view documentation or get support, visit docs.
Installation
Using npm(ES6 module):
Note:
w-websocket-client
is mainly dependent onws
npm i w-websocket-client
Example for w-websocket-client
:
Link: [dev source code]
import WSC from 'w-websocket-client/dist/w-websocket-client.umd.js'
let opt = {
url: 'ws://localhost:8080',
token: '*',
open: function() {
console.log('client nodejs: open')
//send
wsc.send('abc')
},
close: function() {
console.log('client nodejs: close')
},
message: function(data) {
console.log('client nodejs: message', data)
},
error: function(err) {
console.log('client nodejs: error:', err)
},
}
//WSC
let wsc = new WSC(opt)
In a browser(UMD module):
Note:
w-websocket-client
does't depend on any package in browser.
[Optional] Add script with nomodule for IE11.
<script nomodule src="https://cdn.jsdelivr.net/npm/@babel/polyfill/dist/polyfill.min.js"></script>
[Necessary] Add script for w-websocket-client.
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/w-websocket-client.umd.js"></script>
Example for w-websocket-client
:
Link: [dev source code]
//opt
let opt = {
url: 'ws://localhost:8080',
token: '*',
open: function() {
console.log('client web: open')
//send
wsc.send('abc')
},
close: function() {
console.log('client web: close')
},
message: function(data) {
console.log('client web: message', data)
},
error: function(err) {
console.log('client web: error:', err)
},
}
//WSC
let WSC = window['w-websocket-client']
let wsc = new WSC(opt)