Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/broadcast/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createAction } from "@reduxjs/toolkit";

export const REGISTERED = createAction<{ connID: number }>(
"Broadcast/REGISTERING"
);
export const CONNECTED = createAction("Broadcast/CONNECTED");
export const GONE_LIVE = createAction("Broadcast/GONE_LIVE");
export const DISCONNECTED = createAction("Broadcast/DISCONNECTED");
30 changes: 14 additions & 16 deletions src/broadcast/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ConnectionStateEnum } from "./streamer";
import { RecordingStreamer } from "./recording_streamer";
import { audioEngine } from "../mixer/audio";
import { setItemPlayed } from "../showplanner/state";
import { CONNECTED, DISCONNECTED, GONE_LIVE, REGISTERED } from "./actions";

export let streamer: WebRTCStreamer | null = null;

Expand Down Expand Up @@ -62,14 +63,6 @@ const broadcastState = createSlice({
setTracklisting(state, action: PayloadAction<boolean>) {
state.liveForThePurposesOfTracklisting = action.payload;
},
setConnID(state, action: PayloadAction<number | null>) {
state.connID = action.payload;
if (action.payload != null) {
state.stage = "REGISTERED";
} else {
state.stage = "NOT_REGISTERED";
}
},
setWsID(state, action: PayloadAction<string | null>) {
state.wsID = action.payload;
},
Expand All @@ -80,6 +73,11 @@ const broadcastState = createSlice({
state.recordingState = action.payload;
},
},
extraReducers: (builder) =>
builder.addCase(REGISTERED, (state, action) => {
state.connID = action.payload.connID;
state.stage = "REGISTERED";
}),
});

export default broadcastState.reducer;
Expand Down Expand Up @@ -133,7 +131,7 @@ export const registerForShow = (): AppThunk => async (dispatch, getState) => {
);
console.log(connID);
if (connID !== undefined) {
dispatch(broadcastState.actions.setConnID(connID["connid"]));
dispatch(REGISTERED({ connID }));
}
} catch (e) {
if (e instanceof ApiException) {
Expand All @@ -160,9 +158,9 @@ export const cancelTimeslot = (): AppThunk => async (dispatch, getState) => {
console.log("Attempting to Cancel Broadcast.");
try {
var response = await sendBroadcastCancel(getState().broadcast.connID);
dispatch(stopStreaming());
await stopStreaming();
if (response != null) {
dispatch(broadcastState.actions.setConnID(null));
dispatch(DISCONNECTED());
}
} catch (e) {
if (e instanceof ApiException) {
Expand All @@ -181,7 +179,7 @@ export const cancelTimeslot = (): AppThunk => async (dispatch, getState) => {
}
};

export const changeTimeslot = (): AppThunk => async (dispatch, getState) => {
export const changeTimeslot = (): AppThunk => async (_, getState) => {
var state = getState().broadcast;
if (state.stage === "REGISTERED") {
console.log("Attempting to Change Broadcast Options.");
Expand Down Expand Up @@ -309,21 +307,21 @@ export const goOnAir = (): AppThunk => async (dispatch, getState) => {
dispatch
);
streamer.addConnectionStateListener((state) => {
dispatch(broadcastState.actions.setConnectionState(state));
dispatch(CONNECTED);
if (state === "CONNECTION_LOST") {
// un-register if we drop, let the user manually reconnect
dispatch(broadcastState.actions.setConnID(null));
dispatch(DISCONNECTED);
} else if (state === "CONNECTED") {
// okay, we've connected
dispatch(registerForShow());
} else if (state === "LIVE") {
dispatch(setItemPlayed({ itemId: "all", played: false }));
dispatch(GONE_LIVE);
}
});
await streamer.start();
};

export const stopStreaming = (): AppThunk => async (dispatch) => {
export const stopStreaming = async () => {
if (streamer) {
await streamer.stop("stopStreaming call");
streamer = null;
Expand Down
7 changes: 7 additions & 0 deletions src/showplanner/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { AppThunk } from "../store";
import { cloneDeep } from "lodash";
import raygun from "raygun4js";
import { GONE_LIVE } from "../broadcast/actions";

export interface ItemGhost {
type: "ghost";
Expand Down Expand Up @@ -216,6 +217,12 @@ const showplan = createSlice({
state.auxPlaylists = state.auxPlaylists.concat(action.payload);
},
},
extraReducers: (builder) =>
builder.addCase(GONE_LIVE, (state, action) => {
state.plan!.forEach((x) => {
x.played = true;
});
}),
});

export default showplan.reducer;
Expand Down