-
Notifications
You must be signed in to change notification settings - Fork 29
/
SignalR.ts
27 lines (23 loc) · 812 Bytes
/
SignalR.ts
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
import * as SignalR from '@aspnet/signalr'
import * as Utility from './Utility'
export namespace CC98SignalR {
export let connection: SignalR.HubConnection
export let isConnecting: boolean = false
export async function start() {
let token = await Utility.getToken() as string
// remove "Bearer "
token = token.slice(7)
connection = new SignalR.HubConnectionBuilder()
.withUrl('https://api-v2.cc98.org/signalr/notification', {
accessTokenFactory: () => token,
transport: SignalR.HttpTransportType.WebSockets
})
.build();
isConnecting = true
return connection.start()
}
export async function stop() {
isConnecting = false
return connection.stop();
}
}