send wsid to stateserver
This commit is contained in:
parent
8db14adc14
commit
30f3886487
4 changed files with 55 additions and 10 deletions
|
@ -142,6 +142,7 @@ export class WebRTCStreamer extends Streamer {
|
||||||
switch (data.kind) {
|
switch (data.kind) {
|
||||||
case "HELLO":
|
case "HELLO":
|
||||||
console.log("WS HELLO, our client ID is " + data.connectionId);
|
console.log("WS HELLO, our client ID is " + data.connectionId);
|
||||||
|
this.dispatch(BroadcastState.setWsID(data.connectionId));
|
||||||
if (this.state !== "HELLO") {
|
if (this.state !== "HELLO") {
|
||||||
this.ws!.close();
|
this.ws!.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ export type BroadcastStageEnum =
|
||||||
interface BroadcastState {
|
interface BroadcastState {
|
||||||
stage: BroadcastStageEnum;
|
stage: BroadcastStageEnum;
|
||||||
connID: number | null;
|
connID: number | null;
|
||||||
|
wsID: string | null;
|
||||||
sourceID: number;
|
sourceID: number;
|
||||||
autoNewsBeginning: boolean;
|
autoNewsBeginning: boolean;
|
||||||
autoNewsMiddle: boolean;
|
autoNewsMiddle: boolean;
|
||||||
|
@ -37,6 +38,7 @@ const broadcastState = createSlice({
|
||||||
initialState: {
|
initialState: {
|
||||||
stage: "NOT_REGISTERED",
|
stage: "NOT_REGISTERED",
|
||||||
connID: null,
|
connID: null,
|
||||||
|
wsID: null,
|
||||||
sourceID: 5,
|
sourceID: 5,
|
||||||
autoNewsBeginning: true,
|
autoNewsBeginning: true,
|
||||||
autoNewsMiddle: true,
|
autoNewsMiddle: true,
|
||||||
|
@ -66,6 +68,9 @@ const broadcastState = createSlice({
|
||||||
state.stage = "NOT_REGISTERED";
|
state.stage = "NOT_REGISTERED";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setWsID(state, action: PayloadAction<string | null>) {
|
||||||
|
state.wsID = action.payload;
|
||||||
|
},
|
||||||
setConnectionState(state, action: PayloadAction<ConnectionStateEnum>) {
|
setConnectionState(state, action: PayloadAction<ConnectionStateEnum>) {
|
||||||
state.connectionState = action.payload;
|
state.connectionState = action.payload;
|
||||||
},
|
},
|
||||||
|
@ -77,6 +82,12 @@ const broadcastState = createSlice({
|
||||||
|
|
||||||
export default broadcastState.reducer;
|
export default broadcastState.reducer;
|
||||||
|
|
||||||
|
export const {
|
||||||
|
toggleTracklisting,
|
||||||
|
setTracklisting,
|
||||||
|
setWsID
|
||||||
|
} = broadcastState.actions;
|
||||||
|
|
||||||
export interface TrackListItem {
|
export interface TrackListItem {
|
||||||
audiologid: number;
|
audiologid: number;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +100,8 @@ export const changeBroadcastSetting = <K extends keyof BroadcastState>(
|
||||||
dispatch(changeTimeslot());
|
dispatch(changeTimeslot());
|
||||||
};
|
};
|
||||||
|
|
||||||
export const registerTimeslot = (): AppThunk => async (dispatch, getState) => {
|
// intentionally renamed to break all existing callsites
|
||||||
|
export const registerForShow = (): AppThunk => async (dispatch, getState) => {
|
||||||
if (!getState().session.userCanBroadcast) {
|
if (!getState().session.userCanBroadcast) {
|
||||||
dispatch(
|
dispatch(
|
||||||
NavbarState.showAlert({
|
NavbarState.showAlert({
|
||||||
|
@ -104,14 +116,22 @@ export const registerTimeslot = (): AppThunk => async (dispatch, getState) => {
|
||||||
var state = getState().session;
|
var state = getState().session;
|
||||||
const memberid = state.currentUser?.memberid;
|
const memberid = state.currentUser?.memberid;
|
||||||
const timeslotid = state.currentTimeslot?.timeslot_id;
|
const timeslotid = state.currentTimeslot?.timeslot_id;
|
||||||
|
const wsId = getState().broadcast.wsID;
|
||||||
|
if (wsId === null) {
|
||||||
|
console.warn("Tried to register for broadcast with no wsID");
|
||||||
|
}
|
||||||
console.log("Attempting to Register for Broadcast.");
|
console.log("Attempting to Register for Broadcast.");
|
||||||
var sourceid = getState().broadcast.sourceID;
|
var sourceid = getState().broadcast.sourceID;
|
||||||
try {
|
try {
|
||||||
var connID = await sendBroadcastRegister(timeslotid, memberid, sourceid);
|
var connID = await sendBroadcastRegister(
|
||||||
|
timeslotid,
|
||||||
|
memberid,
|
||||||
|
sourceid,
|
||||||
|
wsId || undefined
|
||||||
|
);
|
||||||
console.log(connID);
|
console.log(connID);
|
||||||
if (connID !== undefined) {
|
if (connID !== undefined) {
|
||||||
dispatch(broadcastState.actions.setConnID(connID["connid"]));
|
dispatch(broadcastState.actions.setConnID(connID["connid"]));
|
||||||
dispatch(startStreaming());
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ApiException) {
|
if (e instanceof ApiException) {
|
||||||
|
@ -173,13 +193,18 @@ export const changeTimeslot = (): AppThunk => async (dispatch, getState) => {
|
||||||
export function sendBroadcastRegister(
|
export function sendBroadcastRegister(
|
||||||
timeslotid: number | undefined,
|
timeslotid: number | undefined,
|
||||||
memberid: number | undefined,
|
memberid: number | undefined,
|
||||||
sourceid: number
|
sourceid: number,
|
||||||
|
wsID?: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return broadcastApiRequest("/registerTimeslot", "POST", {
|
const payload = {
|
||||||
memberid: memberid,
|
memberid: memberid,
|
||||||
timeslotid: timeslotid,
|
timeslotid: timeslotid,
|
||||||
sourceid: sourceid
|
sourceid: sourceid
|
||||||
});
|
} as any;
|
||||||
|
if (typeof wsID === "string") {
|
||||||
|
payload["wsid"] = wsID;
|
||||||
|
}
|
||||||
|
return broadcastApiRequest("/registerTimeslot", "POST", payload);
|
||||||
}
|
}
|
||||||
export function sendBroadcastCancel(
|
export function sendBroadcastCancel(
|
||||||
connid: number | null
|
connid: number | null
|
||||||
|
@ -205,8 +230,6 @@ export function sendBroadcastChange(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const { toggleTracklisting, setTracklisting } = broadcastState.actions;
|
|
||||||
|
|
||||||
function shouldTracklist(
|
function shouldTracklist(
|
||||||
optionValue: "always" | "while_live" | "never",
|
optionValue: "always" | "while_live" | "never",
|
||||||
stateValue: boolean
|
stateValue: boolean
|
||||||
|
@ -266,7 +289,17 @@ export function sendTracklistStart(trackid: number): Promise<TrackListItem> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const startStreaming = (): AppThunk => async (dispatch, getState) => {
|
export const goOnAir = (): AppThunk => async (dispatch, getState) => {
|
||||||
|
if (!getState().session.userCanBroadcast) {
|
||||||
|
dispatch(
|
||||||
|
NavbarState.showAlert({
|
||||||
|
color: "warning",
|
||||||
|
content: "You are not WebStudio Trained and cannot go live.",
|
||||||
|
closure: 7000
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log("starting streamer.");
|
console.log("starting streamer.");
|
||||||
streamer = new WebRTCStreamer(MixerState.destination.stream, dispatch);
|
streamer = new WebRTCStreamer(MixerState.destination.stream, dispatch);
|
||||||
streamer.addConnectionStateListener(state => {
|
streamer.addConnectionStateListener(state => {
|
||||||
|
@ -274,6 +307,9 @@ export const startStreaming = (): AppThunk => async (dispatch, getState) => {
|
||||||
if (state === "CONNECTION_LOST") {
|
if (state === "CONNECTION_LOST") {
|
||||||
// un-register if we drop, let the user manually reconnect
|
// un-register if we drop, let the user manually reconnect
|
||||||
dispatch(broadcastState.actions.setConnID(null));
|
dispatch(broadcastState.actions.setConnID(null));
|
||||||
|
} else if (state === "CONNECTED") {
|
||||||
|
// okay, we've connected
|
||||||
|
dispatch(registerForShow());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await streamer.start();
|
await streamer.start();
|
||||||
|
|
|
@ -73,7 +73,7 @@ export function NavBar() {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
switch (broadcastState.stage) {
|
switch (broadcastState.stage) {
|
||||||
case "NOT_REGISTERED":
|
case "NOT_REGISTERED":
|
||||||
dispatch(BroadcastState.registerTimeslot());
|
dispatch(BroadcastState.goOnAir());
|
||||||
break;
|
break;
|
||||||
case "REGISTERED":
|
case "REGISTERED":
|
||||||
dispatch(BroadcastState.cancelTimeslot());
|
dispatch(BroadcastState.cancelTimeslot());
|
||||||
|
|
|
@ -285,6 +285,14 @@ def post_registerCheck() -> Any:
|
||||||
'autoNewsEnd': True,
|
'autoNewsEnd': True,
|
||||||
'wsid': None
|
'wsid': None
|
||||||
}
|
}
|
||||||
|
if "wsid" in content:
|
||||||
|
connection["wsid"] = content["wsid"]
|
||||||
|
if start_time > now_time + datetime.timedelta(minutes=2):
|
||||||
|
# they're late, bring them live now
|
||||||
|
print("({}, {}) late, bringing on air now".format(connection["connid"], connection["wsid"]))
|
||||||
|
do_ws_srv_telnet(connection["wsid"])
|
||||||
|
subprocess.Popen(['sel', '5'])
|
||||||
|
|
||||||
connections.append(connection)
|
connections.append(connection)
|
||||||
print(connections)
|
print(connections)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue