Methods
(static) fire(options)
向目标发送信息
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | 参数对象 Properties
|
(static) on(channel, handler, opts) → {Messager}
接收目标发送过来的信息
Parameters:
Name | Type | Description |
---|---|---|
channel |
消息频道名称 |
|
handler |
消息处理函数 |
|
opts |
Messager参数 |
Returns:
- Type
- Messager
(static) once(channel, handler) → {Messager}
接收目标发送过来的信息, 只接收一次
Parameters:
Name | Type | Description |
---|---|---|
channel |
消息频道名称 |
|
handler |
消息处理函数 |
Returns:
- Type
- Messager
(static) provider(name, origin, handler) → {Messager}
创建服务提供者
Example
// 创建一个服务提供者
const messager = provider({
name: 'MyService',
origin: 'http://localhost:8000/assets/bridge/index.html',
handler: function (data, callback) {
const response = '响应内容'
callback(response)
}
})
// 销毁
messager.destroy()
Parameters:
Name | Type | Description |
---|---|---|
name |
string | 服务名称 |
origin |
string | 自己的桥页面地址 |
handler |
function | 服务消息句柄函数,当服务被调用时触发,参数:data(调用服务传过来的数据),callback响应函数,通过回调响应给调用者 |
Returns:
- Type
- Messager
(static) service(name, bridge, data, origin, callback)
调用消息服务
Example
// 请求服务
service({
name: 'MyService',
bridge: 'http://localhost:8001/app1/assets/bridge/index.html',
origin: 'http://localhost:8000/assets/bridge/index.html',
data: {
id: '123'
},
callback(res) {
console.log('服务响应信息', res)
}
})
Parameters:
Name | Type | Description |
---|---|---|
name |
string | 服务名称 |
bridge |
string | 服务提供方的桥页面地址 |
data |
* | 发送的数据 |
origin |
string | 自己的桥页面地址 |
callback |
function | 回调函数,服务提供方响应的数据通过回调返回 |