new WConverhpClient(opt) → {Object}
- Description:
建立Hapi使用者(Node.js與Browser)端物件
- Source:
Example
import WConverhpClient from 'w-converhp/dist/w-converhp-client.umd.js'
let opt = {
url: 'http://localhost:8080',
apiName: 'api',
}
//new
let wo = new WConverhpClient(opt)
wo.on('open', function() {
console.log('client nodejs: open')
})
wo.on('openOnce', function() {
console.log('client nodejs: openOnce')
//p
let name = 'zdata.b1'
let p = {
a: 12,
b: 34.56,
c: 'test中文',
d: {
name: name,
u8a: new Uint8Array([66, 97, 115]),
//u8a: new Uint8Array(fs.readFileSync('C:\\Users\\Administrator\\Desktop\\'+name)),
}
}
//execute
wo.execute('add', { p },
function (prog, p, m) {
console.log('client nodejs: execute: prog', prog, p, m)
})
.then(function(r) {
console.log('client nodejs: execute: add', r)
})
.catch(function(err) {
console.log('client nodejs: execute: catch', err)
})
//broadcast
wo.broadcast('client nodejs broadcast hi', function (prog) {
console.log('client nodejs: broadcast: prog', prog)
})
.catch(function(err) {
console.log('client nodejs: broadcast: catch', err)
})
//deliver
wo.deliver('client nodejs deliver hi', function (prog) {
console.log('client nodejs: deliver: prog', prog)
})
.catch(function(err) {
console.log('client nodejs: deliver: catch', err)
})
})
wo.on('close', function() {
console.log('client nodejs: close')
})
wo.on('error', function(err) {
console.log('client nodejs: error', err)
})
wo.on('reconn', function() {
console.log('client nodejs: reconn')
})
wo.on('broadcast', function(data) {
console.log('client nodejs: broadcast', data)
})
wo.on('deliver', function(data) {
console.log('client nodejs: deliver', data)
})
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt |
Object | 輸入設定參數物件 Properties
|
Returns:
回傳通訊物件,可監聽事件open、openOnce、close、error、reconn、broadcast、deliver,可使用函數execute、broadcast、deliver
- Type
- Object
Methods
(static) broadcast(data)
- Description:
Hapi通訊物件對伺服器端廣播函數,表示傳送資料給伺服器,還需轉送其他客戶端
- Source:
Example
let data = {...}
wo.broadcast(data)
Parameters:
Name | Type | Description |
---|---|---|
data |
* | 輸入廣播函數之輸入資訊 |
(static) deliver(data)
- Description:
Hapi通訊物件對伺服器端發送函數,表示僅傳送資料給伺服器
- Source:
Example
let data = {...}
wo.deliver(data)
Parameters:
Name | Type | Description |
---|---|---|
data |
* | 輸入發送函數之輸入資訊 |
(static) execute(func, inputopt)
- Description:
Hapi通訊物件對伺服器端執行函數,表示傳送資料給伺服器,並請伺服器執行函數
- Source:
Example
let func = 'NameOfFunction'
let input = {...}
wo.execute(func, input)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
func |
String | 輸入執行函數之名稱字串 |
||
input |
* |
<optional> |
null
|
輸入執行函數之輸入資訊 |
(static) onError(err)
- Description:
Hapi監聽錯誤事件
- Source:
Example
wo.on('error', function(err) {
...
})
Parameters:
Name | Type | Description |
---|---|---|
err |
* | 接收錯誤訊息 |
(static) onOpen()
- Description:
Hapi監聽開啟事件
- Source:
Example
wo.on('open', function() {
...
})
(static) onOpenOnce()
- Description:
Hapi監聽第一次開啟事件
- Source:
Example
wo.on('openOnce', function() {
...
})