Skip to content

Instantly share code, notes, and snippets.

@Stronhold
Last active February 10, 2019 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stronhold/195dd8421b68f88716af189d5c4612e7 to your computer and use it in GitHub Desktop.
Save Stronhold/195dd8421b68f88716af189d5c4612e7 to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { WebSocketSubject } from 'rxjs/webSocket';
@Injectable()
export class WebSocketService {
private _ws: WebSocketSubject<string>;
constructor() { }
connect() {
const webSocketUrl = 'ws://localhost:9000'
this._ws = new WebSocketSubject(webSocketUrl);
this._ws.subscribe((data: string) => {
console.log('Data: ', data);
});
}
sendMessage() {
this._ws.next({type: MessageTypeEnum.ConsoleError, data: null});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment