2023-11-27 17:18:03 +08:00
|
|
|
|
<script setup>
|
2024-01-22 14:49:29 +08:00
|
|
|
|
import { Push } from '@/common/push'
|
|
|
|
|
|
import mitt from "@/utils/mitt";
|
|
|
|
|
|
import {useRoute} from "vue-router";
|
|
|
|
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
|
|
|
|
|
|
console.log(route);
|
|
|
|
|
|
|
|
|
|
|
|
var connection = new Push({
|
|
|
|
|
|
url: 'ws://192.168.1.24:3131', // websocket地址
|
|
|
|
|
|
app_key: 'aaea61749929eb53a4bd75a1474c1d27',
|
|
|
|
|
|
});
|
|
|
|
|
|
// 假设用户uid为1
|
|
|
|
|
|
var uid = 5;
|
|
|
|
|
|
// 浏览器监听user-2频道的消息,也就是用户uid为1的用户消息
|
|
|
|
|
|
var user_channel = connection.subscribe('user-' + uid);
|
|
|
|
|
|
|
|
|
|
|
|
// 当user-2频道有message事件的消息时
|
|
|
|
|
|
user_channel.on('message', function (data) {
|
|
|
|
|
|
mitt.emit(data.content.event, data.content.data);
|
|
|
|
|
|
|
|
|
|
|
|
console.log("收到消息--",data)
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
// 断线事件
|
|
|
|
|
|
user_channel.on('close', function () {
|
|
|
|
|
|
|
|
|
|
|
|
});
|
2023-11-27 17:18:03 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2023-12-05 18:39:17 +08:00
|
|
|
|
<router-view></router-view>
|
2023-11-27 17:18:03 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
* {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|