OSDN Git Service

Implemeted Console service
[eos/zephyr.git] / front-end / app / scripts / services / Console.ts
1 namespace app.services{
2     export class Console {
3         private directiveIDs: string[];
4
5         constructor(private WebSocket: services.WebSocket,
6                     private $rootScope: ng.IRootScopeService
7                    ) {
8             this.WebSocket = WebSocket;
9             this.$rootScope = $rootScope;
10             this.directiveIDs = [];
11
12             const directiveIDs = this.directiveIDs;
13
14             this.WebSocket.on('console', (d) => {
15                 const id = d.id;
16                 const message = d.message;
17                 
18
19                 if(directiveIDs.indexOf(id) > -1) {
20                     $rootScope.$emit(id, message);
21                 }
22             });
23         }
24
25         public addDirective(id: string) {
26             if(!(this.directiveIDs.indexOf(id) > -1)) {
27                 this.directiveIDs.push(id); 
28             }
29         }
30
31         public removeDirective(id: string) {
32             const i = this.directiveIDs.indexOf(id);
33             if(i > -1) {
34                 this.directiveIDs.splice(i,1);
35             }
36         }
37
38         public showIDs() {
39             console.log(this.directiveIDs);
40         }
41     }
42 }