Advertisement
Whistik

Untitled

Aug 4th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Socket } from 'ngx-socket-io'
  3.  
  4. @Injectable({
  5. providedIn: 'root'
  6. })
  7. export class SocketService {
  8.  
  9. constructor(private _socket: Socket) { }
  10.  
  11. get socket() {
  12. return this._socket
  13. }
  14.  
  15. emit(event: string, args: any) {
  16. this._socket.emit(event, args)
  17. }
  18.  
  19. waitForResponse(eventName) {
  20. return new Promise(resolve => {
  21. this._socket.on(eventName, (data) => {
  22. resolve(data)
  23. })
  24. })
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement