diff --git a/src/broadcast/rtc_streamer.ts b/src/broadcast/rtc_streamer.ts index 7ab4cb4..dd05691 100644 --- a/src/broadcast/rtc_streamer.ts +++ b/src/broadcast/rtc_streamer.ts @@ -9,7 +9,7 @@ import { ConnectionStateListener, ConnectionStateEnum } from "./streamer"; -import store from "../store"; +import { Dispatch } from "redux"; type StreamerState = "HELLO" | "OFFER" | "ANSWER" | "CONNECTED"; @@ -19,13 +19,15 @@ export class WebRTCStreamer extends Streamer { ws: WebSocket | undefined; state: StreamerState = "HELLO"; isActive = false; + dispatch: Dispatch; newsInTimeout?: number; newsOutTimeout?: number; - constructor(stream: MediaStream) { + constructor(stream: MediaStream, dispatch: Dispatch) { super(); this.stream = stream; + this.dispatch = dispatch; } async start(): Promise { @@ -186,12 +188,12 @@ export class WebRTCStreamer extends Streamer { case "ACTIVATED": this.isActive = true; this.onStateChange("LIVE"); - store.dispatch(BroadcastState.setTracklisting(true)); + this.dispatch(BroadcastState.setTracklisting(true)); break; case "DEACTIVATED": this.isActive = false; this.onStateChange(this.mapStateToConnectionState()); - store.dispatch(BroadcastState.setTracklisting(false)); + this.dispatch(BroadcastState.setTracklisting(false)); break; case "DIED": // oo-er diff --git a/src/broadcast/state.ts b/src/broadcast/state.ts index 89df269..3d3e0df 100644 --- a/src/broadcast/state.ts +++ b/src/broadcast/state.ts @@ -242,7 +242,7 @@ export function sendTracklistStart(trackid: number): Promise { export const startStreaming = (): AppThunk => async (dispatch, getState) => { console.log("starting streamer."); - streamer = new WebRTCStreamer(MixerState.destination.stream); + streamer = new WebRTCStreamer(MixerState.destination.stream, dispatch); streamer.addConnectionStateListener(state => { dispatch(broadcastState.actions.setConnectionState(state)); if (state === "CONNECTION_LOST") {