fix that dumb shit

This commit is contained in:
Marks Polakovs 2020-04-13 15:05:08 +02:00
parent 9da85215bb
commit 3f569b252a
2 changed files with 7 additions and 5 deletions

View file

@ -9,7 +9,7 @@ import {
ConnectionStateListener, ConnectionStateListener,
ConnectionStateEnum ConnectionStateEnum
} from "./streamer"; } from "./streamer";
import store from "../store"; import { Dispatch } from "redux";
type StreamerState = "HELLO" | "OFFER" | "ANSWER" | "CONNECTED"; type StreamerState = "HELLO" | "OFFER" | "ANSWER" | "CONNECTED";
@ -19,13 +19,15 @@ export class WebRTCStreamer extends Streamer {
ws: WebSocket | undefined; ws: WebSocket | undefined;
state: StreamerState = "HELLO"; state: StreamerState = "HELLO";
isActive = false; isActive = false;
dispatch: Dispatch<any>;
newsInTimeout?: number; newsInTimeout?: number;
newsOutTimeout?: number; newsOutTimeout?: number;
constructor(stream: MediaStream) { constructor(stream: MediaStream, dispatch: Dispatch<any>) {
super(); super();
this.stream = stream; this.stream = stream;
this.dispatch = dispatch;
} }
async start(): Promise<void> { async start(): Promise<void> {
@ -186,12 +188,12 @@ export class WebRTCStreamer extends Streamer {
case "ACTIVATED": case "ACTIVATED":
this.isActive = true; this.isActive = true;
this.onStateChange("LIVE"); this.onStateChange("LIVE");
store.dispatch(BroadcastState.setTracklisting(true)); this.dispatch(BroadcastState.setTracklisting(true));
break; break;
case "DEACTIVATED": case "DEACTIVATED":
this.isActive = false; this.isActive = false;
this.onStateChange(this.mapStateToConnectionState()); this.onStateChange(this.mapStateToConnectionState());
store.dispatch(BroadcastState.setTracklisting(false)); this.dispatch(BroadcastState.setTracklisting(false));
break; break;
case "DIED": case "DIED":
// oo-er // oo-er

View file

@ -242,7 +242,7 @@ export function sendTracklistStart(trackid: number): Promise<TrackListItem> {
export const startStreaming = (): AppThunk => async (dispatch, getState) => { export const startStreaming = (): AppThunk => async (dispatch, getState) => {
console.log("starting streamer."); console.log("starting streamer.");
streamer = new WebRTCStreamer(MixerState.destination.stream); streamer = new WebRTCStreamer(MixerState.destination.stream, dispatch);
streamer.addConnectionStateListener(state => { streamer.addConnectionStateListener(state => {
dispatch(broadcastState.actions.setConnectionState(state)); dispatch(broadcastState.actions.setConnectionState(state));
if (state === "CONNECTION_LOST") { if (state === "CONNECTION_LOST") {