Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Socket } from 'ngx-socket-io';
- import { Document } from '../models/document';
- @Injectable({
- providedIn: 'root'
- })
- export class DocumentService {
- currentDocument = this.socket.fromEvent<Document>('document');
- documents = this.socket.fromEvent<string[]>('documents');
- constructor(private socket: Socket) { }
- getDocument(id: string) {
- this.socket.emit('getDoc', id);
- }
- newDocument() {
- this.socket.emit('addDoc', { id: this.docId(), doc: '' });
- }
- editDocument(document: Document) {
- this.socket.emit('editDoc', document);
- }
- private docId() {
- let text = '';
- const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- for (let i = 0; i < 5; i++) {
- text += possible.charAt(Math.floor(Math.random() * possible.length));
- }
- return text;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement