new types to handle websocket events

This commit is contained in:
Nicolas Constant 2018-09-13 02:02:24 -04:00
parent a40e88573b
commit f129c17dcd
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 24 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import { Injectable } from "@angular/core";
import { Status } from "./models/mastodon.interfaces";
@Injectable()
export class StreamingService {
@ -17,9 +18,31 @@ export class StreamingWrapper {
constructor(private readonly domain: string) {
const eventSource = new WebSocket(domain);
eventSource.onmessage = x => console.warn(JSON.parse(x.data));
eventSource.onmessage = x => this.tootParsing(<WebSocketEvent>JSON.parse(x.data));
eventSource.onerror = x => console.error(x);
eventSource.onopen = x => console.log(x);
eventSource.onclose = x => console.log(x);
}
tootParsing(event: WebSocketEvent){
console.warn(event.event);
console.warn(event.payload);
}
}
class WebSocketEvent {
event: string;
payload: Status;
}
export class StatusUpdate {
type: EventEnum;
status: Status;
}
export enum EventEnum {
unknow = 0,
update = 1,
delete = 2
}