new types to handle websocket events
This commit is contained in:
parent
a40e88573b
commit
f129c17dcd
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue