new WRunqwsClient(optopt) → {Object}
- Description:
建立WebSocket使用者(Node.js與Browser)端物件
Inherit: WConverwsClient
- Source:
- See:
Example
import WRunqwsClient from 'w-runqws/dist/w-runqws-client.umd.js'
let opt = {
url: 'ws://localhost:8080',
token: '*',
}
let missionTopic = 'parser|texts'
//new
let wo = new WRunqwsClient(opt)
wo.on('open', function() {
console.log('client nodejs[port:8080]: open')
// //delQueueByTopic
// wo.delQueueByTopic(missionTopic)
// .then(function(msg) {
// console.log('delQueueByTopic', msg)
// })
//subTopic
wo.subTopic(missionTopic)
function addMission(n) {
//input
let input = '#' + n
//option
let option = {}
//pushQueue
wo.pushQueue(missionTopic, input, option)
}
//mission
let n = 0
let t = setInterval(function() {
n += 1
addMission(n)
if (n === 10) {
clearInterval(t)
}
}, 50)
})
wo.on('openOnce', function() {
console.log('client nodejs[port:8080]: openOnce')
})
wo.on('close', function() {
console.log('client nodejs[port:8080]: close')
})
wo.on('error', function(err) {
console.log('client nodejs[port:8080]: error', err)
})
wo.on('reconn', function() {
console.log('client nodejs[port:8080]: reconn')
})
wo.on('broadcast', function(data) {
console.log('client nodejs[port:8080]: broadcast', data)
})
wo.on('deliver', function(data) {
//console.log('client nodejs[port:8080]: deliver', data)
})
wo.on('queueChange', function(topic, id, input, output, state) {
//console.log('client nodejs[port:8080]: queueChange', topic, id, input, output, state)
console.log('queueChange', input, output, state)
//ready queue
if (topic === missionTopic && state === 'ready') {
setTimeout(function() {
//output
output = 'done(' + input.replace('#', '') + ')'
//state
state = 'finish'
//modifyQueue
wo.modifyQueue(topic, id, input, output, state)
}, 1000)
}
})
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳通訊物件,可監聽事件open、openOnce、close、error、reconn、broadcast、deliver、queueChange,可執行事件pushQueue、modifyQueue、subTopic、unsubTopic、delQueueByTopic、delQueueByID、delQueueByIDs、delQueueByMatches
- Type
- Object
Methods
(static) onQueueChange()
- Description:
監聽佇列變更事件
- Source:
Example
wo.on('queueChange', function() {
...
})
(inner) delQueueByID(id)
- Description:
由佇列id刪除佇列
- Source:
Parameters:
Name | Type | Description |
---|---|---|
id |
String | 輸入佇列id字串 |
(inner) delQueueByIDs(ids)
- Description:
由佇列id陣列刪除佇列
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ids |
Array | 輸入佇列id字串陣列 |
(inner) delQueueByMatches(find)
- Description:
由刪除條件刪除佇列
- Source:
Parameters:
Name | Type | Description |
---|---|---|
find |
Object | 輸入刪除條件物件 |
(inner) delQueueByTopic(topic)
- Description:
由訂閱主題刪除佇列
- Source:
Parameters:
Name | Type | Description |
---|---|---|
topic |
String | 輸入訂閱主題字串 |
(inner) getQueueByID(id)
- Description:
由佇列id取得佇列
- Source:
Parameters:
Name | Type | Description |
---|---|---|
id |
String | 輸入佇列id字串 |
(inner) getQueueByIDs(ids)
- Description:
由佇列id陣列取得佇列
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ids |
Array | 輸入佇列id字串陣列 |
(inner) getQueueByMatches(find)
- Description:
由查詢條件取得佇列
- Source:
Parameters:
Name | Type | Description |
---|---|---|
find |
Object | 輸入取得條件物件 |
(inner) getQueueByTopic(topic)
- Description:
由訂閱主題取得佇列
- Source:
Parameters:
Name | Type | Description |
---|---|---|
topic |
String | 輸入訂閱主題字串 |
(inner) modifyQueue(topic, input, output, state)
- Description:
佇列變更事件
- Source:
Parameters:
Name | Type | Description |
---|---|---|
topic |
String | 輸入主題字串 |
input |
* | 輸入佇列用之輸入任意資訊 |
output |
* | 輸入佇列用之輸出任意資訊 |
state |
String | 輸入佇列用之狀態字串 |
(inner) pushQueue(topic, input, optionopt)
- Description:
佇列發佈事件
- Source:
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
topic |
String | 輸入主題字串 |
||||||||||||||||||||||||||||||||
input |
* | 輸入佇列用之輸入任意資訊 |
||||||||||||||||||||||||||||||||
option |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
(inner) subTopic(topic)
- Description:
訂閱事件
- Source:
Parameters:
Name | Type | Description |
---|---|---|
topic |
String | 輸入欲訂閱主題字串 |
(inner) unsubTopic(topic)
- Description:
取消訂閱事件
- Source:
Parameters:
Name | Type | Description |
---|---|---|
topic |
String | 輸入欲取消主題字串 |