@sambath999/localize-signalr
v12.0.7
Published
localize signalr client app
Downloads
69
Readme
Usage
To use the LocalizeSignalRService
in your Angular application, follow these steps:
Install the
@sambath999/localize-signalr
package by running the following command:npm install @sambath999/localize-signalr
Import the
LocalizeSignalRService
and the required interfaces in your Angular component or service:import { LocalizeSignalRService } from '@sambath999/localize-signalr'; export class YourComponent { // ... }
Create an instance of the
LocalizeSignalRService
in your component or service:export class YourComponent { constructor(private localizeSignalRService: LocalizeSignalRService) { } }
Start the SignalR connection by calling the
startup
method with the required configuration and options:export class YourComponent { constructor(private localizeSignalRService: LocalizeSignalRService) { } ngOnInit() { const config: ILocalizeSignalRConfig = { connectionMethod: 'your-hub-connection-method', hubEndpoint: 'your-hub-endpoint', connections: ['connection1', 'connection2'] }; const options: ILocalizeSignalROptions = { loggingPolicy: { logLevel: signalR.LogLevel.Information, clearConsole: true }, useRxjsOfflineEvent: true, retryPolicy: { limit: 1000, interval: 3 }, accessTokenFactory: () => 'your-access-token', onConnectionState: (connected: boolean) => { console.log('Connection state:', connected); }, onInitialize: async () => { console.log('Initializing connection...'); }, listeners: [ { event: 'event1', recieve: (data: any) => { console.log('Received data:', data); } }, { event: 'event2', recieve: (data: any) => { console.log('Received data:', data); } }, ... ] }; this.localizeSignalRService.startup(config, options) .then(() => { console.log('SignalR connection started successfully.'); }) .catch((error) => { console.error('Failed to start SignalR connection:', error); }); } }
Use the
invoke
method to call methods on the SignalR hub:export class YourComponent { constructor(private localizeSignalRService: LocalizeSignalRService) { } async someMethod() { try { const result = await this.localizeSignalRService.invoke('methodName', arg1, arg2); console.log('Method result:', result); } catch (error) { console.error('Failed to invoke method:', error); } } }
That's it! You can now use the LocalizeSignalRService
to establish a connection to a SignalR hub and interact with it in your Angular application.