Merge branch 'master' into production

This commit is contained in:
Marks Polakovs 2020-04-14 10:11:32 +02:00
commit 2d084987b1
2 changed files with 25 additions and 6 deletions

View file

@ -20,9 +20,11 @@ export class WebRTCStreamer extends Streamer {
state: StreamerState = "HELLO";
isActive = false;
dispatch: Dispatch<any>;
unexpectedDeath = false;
newsInTimeout?: number;
newsOutTimeout?: number;
newsInterval?: number;
constructor(stream: MediaStream, dispatch: Dispatch<any>) {
super();
@ -60,12 +62,17 @@ export class WebRTCStreamer extends Streamer {
}
console.log("ICE Connection state change: " + this.pc.iceConnectionState);
this.onStateChange(this.mapStateToConnectionState());
if (this.mapStateToConnectionState() === "CONNECTED") {
this.doTheNews();
}
};
this.stream.getAudioTracks().forEach(track => this.pc!.addTrack(track));
this.addConnectionStateListener(state => {
if (state === "CONNECTED") {
this.newsInterval = window.setInterval(this.doTheNews, 1000 * 60);
} else if (state === "CONNECTION_LOST" || state === "NOT_CONNECTED") {
window.clearInterval(this.newsInterval);
}
});
console.log("PC created");
this.ws = new WebSocket(process.env.REACT_APP_WS_URL!);
this.ws.onopen = e => {
@ -89,6 +96,7 @@ export class WebRTCStreamer extends Streamer {
this.pc.close();
this.pc = null;
}
this.unexpectedDeath = false;
}
doTheNews() {
@ -97,7 +105,7 @@ export class WebRTCStreamer extends Streamer {
const now = new Date();
if (
now.getMinutes() < 59 ||
(now.getMinutes() === 59 && now.getSeconds() < 45)
(now.getMinutes() === 59 && now.getSeconds() < 44)
) {
const newsTime = DateFns.set(now, {
minutes: 59,
@ -112,7 +120,7 @@ export class WebRTCStreamer extends Streamer {
if (
now.getMinutes() < 1 ||
now.getMinutes() >= 2 ||
(now.getMinutes() === 1 && now.getSeconds() < 50)
(now.getMinutes() === 1 && now.getSeconds() < 54)
) {
let newsEndTime = DateFns.set(now, {
minutes: 1,
@ -201,6 +209,8 @@ export class WebRTCStreamer extends Streamer {
// kill it on our end and trigger a reconnect
await this.stop();
await this.start();
this.unexpectedDeath = true;
break;
}
}
@ -241,7 +251,11 @@ export class WebRTCStreamer extends Streamer {
mapStateToConnectionState(): ConnectionStateEnum {
if (!this.pc) {
return "NOT_CONNECTED";
if (this.unexpectedDeath) {
return "CONNECTION_LOST";
} else {
return "NOT_CONNECTED";
}
}
switch (this.pc.iceConnectionState) {
case "connected":

View file

@ -324,6 +324,7 @@ 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.")
@ -349,13 +350,17 @@ def post_wsSessions() -> Any:
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
print("({}, {}) late, bringing on air now".format(conn["connid"], conn["wsid"]))
do_ws_srv_telnet(conn["wsid"])
subprocess.Popen(['sel', '5'])
if conn["wsid"] in wsids_to_remove:
print("({}, {}) gone".format(conn["connid"], conn["wsid"]))
conn["wsid"] = None
# TODO Make this actually do a disconnect sequence if this is the current show.
# time.sleep(5)