Feat: Emitter for azure-service-hub-adapter#2
Feat: Emitter for azure-service-hub-adapter#2gautam247gk wants to merge 5 commits intosocketio:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds an Emitter class to the Azure Service Bus adapter, enabling remote event emission to Socket.IO servers and clients. The emitter provides a client-side interface for broadcasting messages through Azure Service Bus without needing a full Socket.IO server instance.
- Implements a complete
Emitterclass with namespace, room, and broadcast operator support - Adds TypeScript type definitions for strongly-typed event handling
- Updates documentation with comprehensive usage examples and API reference
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Adds @types/debug dependency for TypeScript support |
| lib/typed-events.ts | Defines TypeScript interfaces for event maps and typed event broadcasting |
| lib/index.ts | Exports the new Emitter class from the main module |
| lib/emitter.ts | Implements the complete Emitter and BroadcastOperator classes with Azure Service Bus integration |
| README.md | Documents emitter usage with examples and API reference |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| @@ -0,0 +1,431 @@ | |||
| // src/index.ts | |||
There was a problem hiding this comment.
The file comment incorrectly references 'src/index.ts' but this file is located at 'lib/emitter.ts'. Update the comment to reflect the correct file path.
| // src/index.ts | |
| // lib/emitter.ts |
| this.sendMessage("", msg); | ||
| } | ||
|
|
||
| private async sendMessage(channel: string, body: any) { |
There was a problem hiding this comment.
The channel parameter is unused in this method. Since it's always called with an empty string, consider removing the parameter to simplify the method signature.
| this.sendMessage("", msg); | |
| } | |
| private async sendMessage(channel: string, body: any) { | |
| this.sendMessage(msg); | |
| } | |
| private async sendMessage(body: any) { |
| this.sendMessage("", msg); | ||
| } | ||
|
|
||
| private async sendMessage(channel: string, body: any) { |
There was a problem hiding this comment.
The channel parameter is unused in this method. Since it's always called with an empty string, consider removing the parameter to simplify the method signature.
| private async sendMessage(channel: string, body: any) { | ||
| debug("sending message to topic"); | ||
| await this.sbSender.sendMessages({ |
There was a problem hiding this comment.
The async method sendMessage is called without awaiting in multiple places (lines 222, 354, 374, 393, 412). This could lead to unhandled promise rejections. Either await these calls or handle the promises appropriately.
| The adapter provides an `Emitter` class that can be used to emit events to all connected servers or clients in a specific namespace. | ||
|
|
||
| ```js | ||
| const { Emitter } = require("socket-io-azure-service-bus-emitter"); |
There was a problem hiding this comment.
The require statement references an incorrect package name 'socket-io-azure-service-bus-emitter'. It should reference the current package '@socket.io/azure-service-bus-adapter' since the Emitter is exported from this package.
| const { Emitter } = require("socket-io-azure-service-bus-emitter"); | |
| const { Emitter } = require("@socket.io/azure-service-bus-adapter"); |
Ive got tests written for this using chai instead of expect.js on https://github.com/gautam247gk/socket-io-azure-service-bus-emitter
Emitter#to(room: string | string[]): BroadcastOperator
Send to specific room(s).
Emitter#in(room: string | string[]): BroadcastOperator
Alias for
.to().Emitter#except(room: string | string[]): BroadcastOperator
Exclude specific room(s).
Emitter#of(namespace: string): Emitter
Send to a specific namespace.
Emitter#volatile: BroadcastOperator
Mark the message as volatile (may be dropped if clients are not ready).
Emitter#compress(compress: boolean): BroadcastOperator
Set compression flag.
Emitter#socketsJoin(rooms: string | string[]): void
Make matching sockets join room(s).
Emitter#socketsLeave(rooms: string | string[]): void
Make matching sockets leave room(s).
Emitter#disconnectSockets(close?: boolean): void
Disconnect matching sockets.
Emitter#serverSideEmit(...args: any[]): void
Emit a message to all servers in the cluster (server-to-server communication).