From 7c8eff552048d364595a0d78eaf491924f99e4f9 Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Fri, 17 Apr 2020 16:45:39 +0200 Subject: [PATCH] Remove old "lastConnection" logic --- src/broadcast/state.ts | 12 +++++------- stateserver.py | 26 ++++++++------------------ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/broadcast/state.ts b/src/broadcast/state.ts index 628037c..90e9a14 100644 --- a/src/broadcast/state.ts +++ b/src/broadcast/state.ts @@ -118,7 +118,7 @@ export const registerForShow = (): AppThunk => async (dispatch, getState) => { const timeslotid = state.currentTimeslot?.timeslot_id; const wsId = getState().broadcast.wsID; if (wsId === null) { - console.warn("Tried to register for broadcast with no wsID"); + throw new Error("Tried to register for broadcast with no wsID"); } console.log("Attempting to Register for Broadcast."); var sourceid = getState().broadcast.sourceID; @@ -127,7 +127,7 @@ export const registerForShow = (): AppThunk => async (dispatch, getState) => { timeslotid, memberid, sourceid, - wsId || undefined + wsId ); console.log(connID); if (connID !== undefined) { @@ -197,16 +197,14 @@ export function sendBroadcastRegister( timeslotid: number | undefined, memberid: number | undefined, sourceid: number, - wsID?: string + wsID: string ): Promise { const payload = { memberid: memberid, timeslotid: timeslotid, - sourceid: sourceid + sourceid: sourceid, + wsid: wsID } as any; - if (typeof wsID === "string") { - payload["wsid"] = wsID; - } return broadcastApiRequest("/registerTimeslot", "POST", payload); } export function sendBroadcastCancel( diff --git a/stateserver.py b/stateserver.py index dfc7879..aa329e1 100755 --- a/stateserver.py +++ b/stateserver.py @@ -80,7 +80,6 @@ SOURCES = [SOURCE_JUKEBOX, SOURCE_OB, SOURCE_WS, SOURCE_OFFAIR] # This array will only hold connections we've validated to be authorised to broadcast. connections: List[Connection] = [] wsSessions: Dict[str, Dict[str, str]] = {} -lastConnectionIDToRegister = -1 def getCurrentShowConnection() -> Optional[Connection]: @@ -228,7 +227,6 @@ def post_cancelCheck() -> Any: @app.route('/api/v1/registerTimeslot', methods=['POST']) def post_registerCheck() -> Any: global connections - global lastConnectionIDToRegister content = request.json if not content: @@ -241,6 +239,8 @@ def post_registerCheck() -> Any: return genFail("Request missing valid source.") if not content["sourceid"] in SOURCES: return genFail("Request missing valid source.") + if not isinstance(content["wsid"], str): + return genFail("Request missing valid wsID") member = myradioApiRequest("user/" + str(content["memberid"])) if not member: @@ -294,23 +294,19 @@ def post_registerCheck() -> Any: 'autoNewsBeginning': True, 'autoNewsMiddle': True, 'autoNewsEnd': True, - 'wsid': None + 'wsid': content["wsid"] } - if "wsid" in content: - connection["wsid"] = content["wsid"] - if start_time + datetime.timedelta(minutes=2) < now_time: - # 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']) + if start_time + datetime.timedelta(minutes=2) < now_time: + # 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']) assert connection is not None connections.append(connection) print(connections) - lastConnectionIDToRegister = connection["connid"] - return genPayload(connection) @@ -345,7 +341,6 @@ def post_settingsCheck() -> Any: def post_wsSessions() -> Any: global connections global wsSessions - global lastConnectionIDToRegister content = request.json # if not content: # return genFail("No parameters provided.") @@ -368,11 +363,6 @@ def post_wsSessions() -> Any: print("wsSessions which have appeared:", wsids_to_add) for conn in connections: - if conn["connid"] == lastConnectionIDToRegister: - if conn["wsid"] is None and len(wsids_to_add) == 1: - conn["wsid"] = wsids_to_add[0] - print("({}, {}) hello".format(conn["connid"], conn["wsid"])) - if conn["wsid"] in wsids_to_add: if conn["startTimestamp"] + 120 < datetime.datetime.now().timestamp(): # they're late, bring them on air now