|
@@ -1,3 +1,11 @@
|
|
|
+/*
|
|
|
+ * @Author: zc
|
|
|
+ * @Description:
|
|
|
+ * @version:
|
|
|
+ * @Date: 2022-10-21 09:01:23
|
|
|
+ * @LastEditors: Please set LastEditors
|
|
|
+ * @LastEditTime: 2022-10-25 16:45:06
|
|
|
+ */
|
|
|
// 官方文档:https://docs.microsoft.com/zh-cn/aspnet/core/signalr/javascript-client?view=aspnetcore-6.0&viewFallbackFrom=aspnetcore-2.2&tabs=visual-studio
|
|
|
import * as signalR from '@microsoft/signalr'
|
|
|
import { ElNotification } from 'element-plus'
|
|
@@ -9,11 +17,9 @@ export default {
|
|
|
failNum: 4,
|
|
|
baseUrl: '',
|
|
|
init(url:string) {
|
|
|
- // var socketUrl = window.location.origin + url;
|
|
|
- const socketUrl = "http://192.168.100.22:50001" + url;
|
|
|
const token = Session.get("token")
|
|
|
const connection = new signalR.HubConnectionBuilder()
|
|
|
- .withUrl(socketUrl, { accessTokenFactory:() => token,skipNegotiation: true, transport : 1 })
|
|
|
+ .withUrl(url, { accessTokenFactory:() => token,skipNegotiation: true, transport : 1 })
|
|
|
.withAutomaticReconnect() //自动重新连接
|
|
|
.configureLogging(signalR.LogLevel.Warning)
|
|
|
.build();
|
|
@@ -45,7 +51,7 @@ export default {
|
|
|
//使用async和await 或 promise的then 和catch 处理来自服务端的异常
|
|
|
await this.SR.start()
|
|
|
//console.assert(this.SR.state === signalR.HubConnectionState.Connected);
|
|
|
- console.log('signalR', this.SR.state);
|
|
|
+ console.log('signalR', this.SR.state,'链接状态');
|
|
|
return true
|
|
|
} catch (error){
|
|
|
that.failNum--;
|
|
@@ -61,9 +67,9 @@ export default {
|
|
|
// 接收消息处理
|
|
|
receiveMsg(connection:any) {
|
|
|
// 接收欢迎语
|
|
|
- connection.on("Ring", (data:any) => {
|
|
|
- console.log(data)
|
|
|
- });
|
|
|
+ // connection.on("Ring", (data:any) => {
|
|
|
+ // console.log(data)
|
|
|
+ // });
|
|
|
// 接收后台手动推送消息
|
|
|
connection.on("receiveNotice", (title:string, data:any) => {
|
|
|
ElNotification({
|