Methods
WWebsocketClient(opt) → {Promise}
- Description:
建立WebSocket使用者(Node.js與Browser)端物件
- Source:
Example
import WSC from 'w-websocket-client/dist/w-websocket-client.umd.js'
//opt
let opt = {
url: 'ws://localhost:8080',
token: '*',
open: function() {
console.log('client: open')
},
close: function() {
console.log('client: close')
},
message: function(data) {
console.log('client: message', data)
},
error: function(err) {
console.log('client: error:', err)
},
}
//wsc
let wsc = null
new WSC(opt)
.then(function(w){
//save
wsc = w
//send
let data = 'abc'
wsc.send(data)
})
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt |
Object | 輸入設定參數物件 Properties
|
Returns:
回傳Promise,resolve為回傳連接成功的Websocket物件,reject回傳為無法連接
- Type
- Promise