1- import * as SR from '@microsoft/signalr' ;
1+ import {
2+ HttpTransportType ,
3+ type HubConnection ,
4+ HubConnectionBuilder ,
5+ HubConnectionState ,
6+ LogLevel ,
7+ } from '@microsoft/signalr' ;
28import { browser , dev } from '$app/environment' ;
39import { PUBLIC_BACKEND_API_DOMAIN } from '$env/static/public' ;
410import { UserStore } from '$lib/stores/UserStore' ;
@@ -12,41 +18,41 @@ import {
1218 handleSignalrOtaInstallSucceeded ,
1319} from './handlers/OtaInstall' ;
1420
15- const signalr_connection = writable < SR . HubConnection | null > ( null ) ;
16- const signalr_state = writable < SR . HubConnectionState > ( SR . HubConnectionState . Disconnected ) ;
21+ const signalr_connection = writable < HubConnection | null > ( null ) ;
22+ const signalr_state = writable < HubConnectionState > ( HubConnectionState . Disconnected ) ;
1723
1824async function create_signalr_connection ( ) {
1925 let connection = get ( signalr_connection ) ;
2026 if ( connection ) {
2127 return ;
2228 }
2329
24- connection = new SR . HubConnectionBuilder ( )
25- . configureLogging ( dev ? SR . LogLevel . Debug : SR . LogLevel . Information )
30+ connection = new HubConnectionBuilder ( )
31+ . configureLogging ( dev ? LogLevel . Debug : LogLevel . Information )
2632 . withUrl ( `https://${ PUBLIC_BACKEND_API_DOMAIN } /1/hubs/user` , {
27- transport : SR . HttpTransportType . WebSockets ,
33+ transport : HttpTransportType . WebSockets ,
2834 skipNegotiation : true ,
2935 } )
3036 . withAutomaticReconnect ( [ 0 , 1000 , 2000 , 5000 , 10000 , 10000 , 15000 , 30000 , 60000 ] )
3137 . build ( ) ;
3238
3339 connection . onclose ( ( ) => {
34- signalr_state . set ( SR . HubConnectionState . Disconnected ) ;
40+ signalr_state . set ( HubConnectionState . Disconnected ) ;
3541 } ) ;
3642
3743 connection . onreconnecting ( ( ) => {
38- signalr_state . set ( SR . HubConnectionState . Reconnecting ) ;
44+ signalr_state . set ( HubConnectionState . Reconnecting ) ;
3945 } ) ;
4046
4147 connection . onreconnected ( ( ) => {
42- signalr_state . set ( SR . HubConnectionState . Connected ) ;
48+ signalr_state . set ( HubConnectionState . Connected ) ;
4349 } ) ;
4450
4551 connection . on ( 'Welcome' , ( message ) => {
4652 console . log ( message ) ;
4753 } ) ;
4854
49- connection . on ( 'Log' , ( log ) => { } ) ;
55+ connection . on ( 'Log' , ( ) => { } ) ;
5056
5157 connection . on ( 'DeviceStatus' , handleSignalrDeviceState ) ;
5258 connection . on ( 'DeviceUpdate' , handleSignalrDeviceUpdate ) ;
@@ -71,11 +77,11 @@ function destroy_signalr_connection() {
7177
7278export const SignalR_State = {
7379 subscribe : signalr_state . subscribe ,
74- } as Readable < SR . HubConnectionState > ;
80+ } as Readable < HubConnectionState > ;
7581
7682export const SignalR_Connection = {
7783 subscribe : signalr_connection . subscribe ,
78- } as Readable < SR . HubConnection | null > ;
84+ } as Readable < HubConnection | null > ;
7985
8086export function initializeSignalR ( ) {
8187 if ( ! browser ) return ;
@@ -86,12 +92,12 @@ export function initializeSignalR() {
8692 } else {
8793 create_signalr_connection ( )
8894 . then ( ( ) => {
89- signalr_state . set ( SR . HubConnectionState . Connected ) ;
95+ signalr_state . set ( HubConnectionState . Connected ) ;
9096 } )
9197 . catch ( ( e ) => {
9298 console . error ( e ) ;
9399 toast . error ( 'Failed to connect to server!' ) ;
94- signalr_state . set ( SR . HubConnectionState . Disconnected ) ;
100+ signalr_state . set ( HubConnectionState . Disconnected ) ;
95101 } ) ;
96102 }
97103 } ) ;
0 commit comments