Skip to content

Instantly share code, notes, and snippets.

@mcgill-a
Last active September 25, 2023 12:36
Show Gist options
  • Save mcgill-a/9c3614132b842f217fa8c97bdfa43e0e to your computer and use it in GitHub Desktop.
Save mcgill-a/9c3614132b842f217fa8c97bdfa43e0e to your computer and use it in GitHub Desktop.
A minimal frontend service for listening to web socket changes in Angular
@Injectable({ providedIn: 'root' })
export class SocketService {
constructor(private socket: Socket) {}
public readonly userChange = this.socket
.fromEvent<string>(SocketChannel.user)
.pipe(map((x) => JSON.parse(x) as UserChange));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment