Skip to content

bsssshhhhhhh/signalr-event-emitter

Repository files navigation

signalr-event-emitter

npm

A utility function that allows for receiving method invocations from a SignalR hub in a type-safe way

Why?

The createSignalrEventEmitter function in this package allows for defining event names and parameters via TypeScript

Example

// build hub connection
const hubConnection = new signalR.HubConnectionBuilder()
  .withUrl('/somehub')
  .build();


// define method names and the parameters expected
interface Methods {
  started: () => void;
  progress: (processedCount: number, totalCount: number) => void;
  finished: () => void;
}

// attach emitter
const emitter = createSignalrEventEmitter<Methods>(hubConnection);


emitter.on('progress', (processedCount, totalCount) => {

});

About

Making SignalR hubs slightly easier to use with TypeScript

Resources

License

Stars

Watchers

Forks

Packages

No packages published