communication.service.ts 2.04 KB
Newer Older
Tomislav Pree's avatar
Tomislav Pree committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { WebsocketService } from './websocket.service';
import { environment } from '../environments/environment'
import { map } from "rxjs/operators";


export interface Message {
  tag: string,
  path: String
}

export interface StartDebuggerRequest {
  tag: string,
  code: String
}

export interface ContinueRequest {
  tag: string
}

export interface RefreshRequest {
  tag: string
}

export interface StepRequest {
  tag: string
}

@Injectable({
  providedIn: 'root'
})


export class CommunicationService {
  public messages: Subject<Message>;
  public startDebuggerRequests: Subject<StartDebuggerRequest>;
  public continueRequests: Subject<ContinueRequest>;
  public refreshRequests: Subject<RefreshRequest>;
  public stepRequests: Subject<StepRequest>;

  constructor(private wsService: WebsocketService) {

    this.messages = <Subject<Message>>wsService
    .connect(environment.CHAT_URL)
    .pipe(map((response: MessageEvent): Message => {
      let data = JSON.parse(response.data);
      
      return data
    }))

    this.startDebuggerRequests = <Subject<StartDebuggerRequest>>wsService
    .connect(environment.CHAT_URL)
    .pipe(map((response: MessageEvent): StartDebuggerRequest => {
      let data = JSON.parse(response.data);
      
      return data
    }))

    this.continueRequests = <Subject<ContinueRequest>>wsService
    .connect(environment.CHAT_URL)
    .pipe(map((response: MessageEvent): ContinueRequest => {
      let data = JSON.parse(response.data);
      
      return data
    }))

    this.refreshRequests = <Subject<RefreshRequest>>wsService
    .connect(environment.CHAT_URL)
    .pipe(map((response: MessageEvent): RefreshRequest => {
      let data = JSON.parse(response.data);
      
      return data
    }))

    this.stepRequests = <Subject<StepRequest>>wsService
    .connect(environment.CHAT_URL)
    .pipe(map((response: MessageEvent): StepRequest => {
      let data = JSON.parse(response.data);
      
      return data
    }))
   
   }


}