webman pusher 推送服务应用插件
6¥
类型
应用插件
版本
0.0.1
版本更新时间
2023-02-24
大小
4.44 MB
开发商
hsk99
评分
详细介绍
基于 webman + GatewayWorker 开发的一个推送服务应用插件,客户端基于订阅模式 兼容 pusher。
功能特性
- 基于 GatewayWorker 多进程运行
- 推送数据统计
- 推送记录存储
- 客户端兼容 pusher
- webhooks
安装使用
下载
下载源码放入plugin目录下,restart重启webman。
访问
访问 http://127.0.0.1:8787/app/pusher 会自动进入安装页面,按照提示安装组件,设置数据库、Redis及Pusher配置信息。
安装配置完成后 关闭重启webman
,即可使用。
文档
订阅发布
\plugin\pusher\app\service\Channel::publish(
'public', // channel
'message', // event
json_encode([1, 2, 3, 4, 5, 6, 7, 8, 9]), // data
null // exclude_socket_id
);
在线订阅channel列表
\plugin\pusher\app\service\Channel::list($type = null); // $type: public、private、presence
在线订阅channel详情
\plugin\pusher\app\service\Channel::info($channel);
Pusher.js 客户端使用
// connect
var id = Math.ceil(Math.random() * 100);
var pusher = new Pusher("ac584d0fde81dedab1ec8dd1ac51c2db", {
forceTLS: false,
wsHost: '127.0.0.1',
wsPort: 8801,
channelAuthorization: {
endpoint: 'http://127.0.0.1:8787/app/pusher/connect/auth',
params: {
access_key: "ac584d0fde81dedab1ec8dd1ac51c2db",
user_id: id,
user_info: JSON.stringify({ 'name': '张三' + id })
}
}
})
// error
pusher.connection.bind("error", function (err) {
console.log(JSON.stringify(err));
// disconnect
if (-1 === err.data.code) {
pusher.connection.disconnect();
}
});
// Public channels
var public = pusher.subscribe('public');
// Subscription succeeded
public.bind("pusher:subscription_succeeded", () => {
console.log('public subscription_succeeded');
});
// custom event
public.bind('message', function (data) {
console.log('public-message:' + JSON.stringify(data));
});
// Private channels
var private = pusher.subscribe('private-message');
// Subscription succeeded
private.bind("pusher:subscription_succeeded", () => {
console.log('private subscription_succeeded');
});
// custom event
private.bind('client-message', function (data) {
console.log('private-client-message:' + JSON.stringify(data));
});
// Private channels (Client push)
var client = pusher.subscribe('private-push');
// custom event
client.bind('message', function (data) {
console.log('client-push-message:' + JSON.stringify(data));
private.trigger('client-message', JSON.stringify(data));
});
// Presence channels
var presence = pusher.subscribe("presence-message");
// Subscription succeeded
presence.bind("pusher:subscription_succeeded", (data) => {
console.log('presence subscription_succeeded:' + JSON.stringify(data));
});
// add member
presence.bind("pusher:member_added", (data) => {
console.log('member_added:' + JSON.stringify(data));
});
// remove member
presence.bind("pusher:member_removed", (data) => {
console.log('member_removed:' + JSON.stringify(data));
});
// custom event
presence.bind("message", (data) => {
console.log('member_removed:' + JSON.stringify(data));
});
WebHooks
请求方式
- POST
Header
|Header|类型|说明|
|:---- |:----- |----- |
|x-pusher-signature |string |签名 |
签名:
hash_hmac('sha256', 请求数据包, 密钥, false)
请求数据
{
"time_ms": 1661132991.891466,
"events": {
"channel_added": [
{
"type": "public",
"channel": "public"
},
{
"type": "private",
"channel": "private-message"
}
],
"channel_removed": [
{
"type": "private",
"channel": "private-push"
},
{
"type": "presence",
"channel": "presence-message"
}
],
"user_added": {
"presence-message": [
{
"channel": "presence-message",
"user_id": 49,
"user_info": "{\"name\":\"张三49\"}"
}
]
},
"user_removed": {
"presence-message": [
{
"channel": "presence-message",
"user_id": 37,
"user_info": "{\"name\":\"张三37\"}"
}
]
}
}
}
数据说明
整个数据包为
JSON
数据
|参数名|类型|说明|
|:---- |:----- |----- |
|time_ms |string |毫秒时间戳 |
|events |array | 事件 |
版本历史记录
0.0.1
2023-02-23
webman pusher 推送服务应用插件
评分及评论
5
满分5分
cbw7172002 2023-05-04
数据库安装时候错误,但没提示
飞老鼠 2023-04-03
new Pusher() 里面不添加cluster: 'APP_CLUSTER' 报错