Skip to content

Commit 07713d7

Browse files
committed
feat:新增push-vue.js文件
docs:调整readme
1 parent b4c87c9 commit 07713d7

File tree

2 files changed

+804
-1
lines changed

2 files changed

+804
-1
lines changed

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
11
# push
22
webman push plugin
3-
https://www.workerman.net/plugin/2
3+
具体使用请看:https://www.workerman.net/plugin/2
4+
5+
## js文件说明
6+
7+
---
8+
9+
```sh
10+
push-uniapp.js #适用于uniapp项目内使用
11+
push-vue.js #适用于vue项目内使用
12+
push.js #适用于直接引入js常规项目内使用
13+
```
14+
15+
### push-vue.js 使用说明
16+
17+
---
18+
19+
1、将文件 push-vue.js复制到项目目录下,如:src/utils/push-vue.js
20+
21+
2、在vue页面内引入
22+
```js
23+
24+
<script lang="ts" setup>
25+
import { onMounted } from 'vue'
26+
import { Push } from '../utils/push-vue'
27+
28+
onMounted(() => {
29+
console.log('组件已经挂载')
30+
31+
//实例化webman-push
32+
33+
// 建立连接
34+
var connection = new Push({
35+
url: 'ws://127.0.0.1:3131', // websocket地址
36+
app_key: '<app_key,在config/plugin/webman/push/app.php里获取>',
37+
auth: '/plugin/webman/push/auth' // 订阅鉴权(仅限于私有频道)
38+
});
39+
40+
// 假设用户uid为1
41+
var uid = 1;
42+
// 浏览器监听user-1频道的消息,也就是用户uid为1的用户消息
43+
var user_channel = connection.subscribe('user-' + uid);
44+
45+
// 当user-1频道有message事件的消息时
46+
user_channel.on('message', function (data) {
47+
// data里是消息内容
48+
console.log(data);
49+
});
50+
// 当user-1频道有friendApply事件时消息时
51+
user_channel.on('friendApply', function (data) {
52+
// data里是好友申请相关信息
53+
console.log(data);
54+
});
55+
56+
// 假设群组id为2
57+
var group_id = 2;
58+
// 浏览器监听group-2频道的消息,也就是监听群组2的群消息
59+
var group_channel = connection.subscribe('group-' + group_id);
60+
// 当群组2有message消息事件时
61+
group_channel.on('message', function (data) {
62+
// data里是消息内容
63+
console.log(data);
64+
});
65+
66+
67+
})
68+
69+
</script>
70+
71+
```
72+
73+
74+

0 commit comments

Comments
 (0)