Skip to content

Feat: Emitter for azure-service-hub-adapter#2

Open
gautam247gk wants to merge 5 commits intosocketio:mainfrom
gautam247gk:main
Open

Feat: Emitter for azure-service-hub-adapter#2
gautam247gk wants to merge 5 commits intosocketio:mainfrom
gautam247gk:main

Conversation

@gautam247gk
Copy link

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).

Copilot AI review requested due to automatic review settings September 1, 2025 21:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Emitter class 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
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// src/index.ts
// lib/emitter.ts

Copilot uses AI. Check for mistakes.
Comment on lines +222 to +225
this.sendMessage("", msg);
}

private async sendMessage(channel: string, body: any) {
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
this.sendMessage("", msg);
}
private async sendMessage(channel: string, body: any) {
this.sendMessage(msg);
}
private async sendMessage(body: any) {

Copilot uses AI. Check for mistakes.
this.sendMessage("", msg);
}

private async sendMessage(channel: string, body: any) {
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +225 to +227
private async sendMessage(channel: string, body: any) {
debug("sending message to topic");
await this.sbSender.sendMessages({
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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");
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
const { Emitter } = require("socket-io-azure-service-bus-emitter");
const { Emitter } = require("@socket.io/azure-service-bus-adapter");

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants