使用signalr-client

signalr client

基于 @microsoft/signalr 客户端

使用

yarn add facade-signalr-client

js 客户端使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import signalrClient from 'facade-signalr-client'

try {
// register events signalr.connected
signalrClient.events.on('signalr.connected', connection => {
console.log(connection, 'signalr.connected')
})

// connect
signalrClient.connect('baseUrl', queryString)

// Received
signalrClient.receiveMessage('ReceivedMethod', arg => {
console.log('Received:' + arg)
})
} catch (err) {
console.log(err)
}

// Send message
signalrClient.sendMessage('SendMethod', 'args').then(response => {
console.log('response:' + response)
})

服务端 使用

1
2
3
4
5
public async Task<string> SendMethod(string args)
{
await Clients.All.SendAsync("ReceivedMethod", args);
return "发送成功";
}