loulijun2021
2023-07-19 5cf009d5ee7cd782a360848d5c2d7b71aec4d8af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as signalR from '@aspnet/signalr'
 
const url = 'http://121.196.36.24:8019/chatHub'
const signal = new signalR.HubConnectionBuilder()
  .withUrl(url, {
    // skipNegotiation: true,
    // transport: signalR.HttpTransportType.WebSockets
  })
  .configureLogging(signalR.LogLevel.Information)
  .build()
// signal.on('SendAll', (res) => {
//   console.log(res, '收到消息了')
// })
signal.start().then(() => {
  if (window.Notification) {
    if (Notification.permission === 'granted') {
      console.log('允许通知')
    } else if (Notification.permission !== 'denied') {
      console.log('需要通知权限')
      Notification.requestPermission((permission) => {
        console.log('权限通知', permission)
      })
    } else if (Notification.permission === 'denied') {
      console.log('拒绝通知')
    }
  } else {
    console.error('浏览器不支持Notification')
  }
  console.log('连接成功')
})
// signal.onclose((err) => {
//   console.log('连接已经断开 执行函数onclose', err)
// })
export default {
  signal
}