Advertisement
selvalives

Untitled

Aug 8th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Socket } from 'ngx-socket-io';
  3. import { Document } from '../models/document';
  4.  
  5. @Injectable({
  6. providedIn: 'root'
  7. })
  8. export class DocumentService {
  9. currentDocument = this.socket.fromEvent<Document>('document');
  10. documents = this.socket.fromEvent<string[]>('documents');
  11.  
  12. constructor(private socket: Socket) { }
  13.  
  14. getDocument(id: string) {
  15. this.socket.emit('getDoc', id);
  16. }
  17.  
  18. newDocument() {
  19. this.socket.emit('addDoc', { id: this.docId(), doc: '' });
  20. }
  21.  
  22. editDocument(document: Document) {
  23. this.socket.emit('editDoc', document);
  24. }
  25.  
  26. private docId() {
  27. let text = '';
  28. const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  29.  
  30. for (let i = 0; i < 5; i++) {
  31. text += possible.charAt(Math.floor(Math.random() * possible.length));
  32. }
  33.  
  34. return text;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement