2018-03-22 05:31:34 +01:00
|
|
|
import { Injectable } from "@angular/core";
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class StreamingService {
|
|
|
|
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
//TODO restructure this to handle real domain objects
|
2018-09-13 06:50:27 +02:00
|
|
|
getStreaming(instance: string, accessToken: string): StreamingWrapper {
|
|
|
|
const route = `wss://${instance}/api/v1/streaming?access_token=${accessToken}&stream=public`
|
|
|
|
return new StreamingWrapper(route);
|
2018-03-22 05:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export class StreamingWrapper {
|
|
|
|
|
|
|
|
constructor(private readonly domain: string) {
|
|
|
|
const eventSource = new WebSocket(domain);
|
|
|
|
eventSource.onmessage = x => console.warn(JSON.parse(x.data));
|
|
|
|
eventSource.onerror = x => console.error(x);
|
|
|
|
eventSource.onopen = x => console.log(x);
|
|
|
|
eventSource.onclose = x => console.log(x);
|
|
|
|
}
|
|
|
|
}
|