Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ServeSocketService
✓ import { ServeSocketService } from 'serve-socket';
✗ const { ServeSocketService } = require('serve-socket');
Library is ESM-only and ships TypeScript declarations.
WaiterEvent
✓ import { WaiterEvent } from 'serve-socket';
✗ import { WaiterEvent } from 'serve-socket/models';
All types are exported from the main entry point.
OrderStatus
✓ import { OrderStatus } from 'serve-socket';
✗ import { OrderStatus } from 'serve-socket/enums';
Enum is re-exported from the root module.
ServeSocketModule
✓ import { ServeSocketModule } from 'serve-socket';
✗ import { ServeSocketModule } from 'serve-socket/serve-socket.module';
Import the module directly from the package root for Angular usage.
Demonstrates importing ServeSocketModule, configuring the MQTT broker, and using the service to emit and listen for WebSocket events.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ServeSocketModule } from 'serve-socket';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
ServeSocketModule.forRoot({ brokerUrl: process.env['MQTT_BROKER'] ?? 'ws://localhost:9001' })
],
bootstrap: [AppComponent]
})
export class AppModule {}
import { Component, OnInit } from '@angular/core';
import { ServeSocketService, WaiterEvent } from 'serve-socket';
@Component({
selector: 'app-waiter',
template: '<button (click)="callWaiter()">Call Waiter</button>'
})
export class WaiterComponent implements OnInit {
constructor(private serveSocket: ServeSocketService) {}
ngOnInit() {
this.serveSocket.on('order-ready', (event: WaiterEvent) => {
console.log('Order ready:', event.tableId);
});
}
callWaiter() {
this.serveSocket.emit('call-waiter', { tableId: 5 });
}
}
Errors
Common errors & fixes
Error: Can't resolve 'mqtt'
Missing mqtt peer dependency
fixnpm install mqtt@>=5.0.0
NullInjectorError: No provider for ServeSocketService!
ServeSocketModule not imported or not configured via forRoot()
fixAdd ServeSocketModule.forRoot(...) to your root NgModule imports.
Property 'emitCallWaiter' does not exist on type 'ServeSocketService'
API changed; method renamed in v6
fixUse emit('call-waiter', ...) instead of emitCallWaiter. Audit
Dependencies
@angular/commonrequiredProvides Angular HTTP client and common services
@angular/corerequiredRequired for Angular dependency injection and lifecycle
mqttrequiredUsed for MQTT protocol communication with the broker