Lf94/eco mode save the planet (#2940)
* Trigger shutdown operations after each test * Idle mode states * Don't show the reconnect when coming back from tab
This commit is contained in:
@ -300,6 +300,7 @@ class EngineConnection extends EventTarget {
|
||||
pc?: RTCPeerConnection
|
||||
unreliableDataChannel?: RTCDataChannel
|
||||
mediaStream?: MediaStream
|
||||
freezeFrame: boolean = false
|
||||
|
||||
private _state: EngineConnectionState = {
|
||||
type: EngineConnectionStateType.Fresh,
|
||||
@ -365,7 +366,11 @@ class EngineConnection extends EventTarget {
|
||||
this.pingPongSpan = { ping: undefined, pong: undefined }
|
||||
|
||||
// Without an interval ping, our connection will timeout.
|
||||
// If this.freezeFrame is true we skip this logic so only reconnect
|
||||
// happens on mouse move
|
||||
setInterval(() => {
|
||||
if (this.freezeFrame) return
|
||||
|
||||
switch (this.state.type as EngineConnectionStateType) {
|
||||
case EngineConnectionStateType.ConnectionEstablished:
|
||||
// If there was no reply to the last ping, report a timeout.
|
||||
@ -426,7 +431,8 @@ class EngineConnection extends EventTarget {
|
||||
return this.state.type === EngineConnectionStateType.ConnectionEstablished
|
||||
}
|
||||
|
||||
tearDown() {
|
||||
tearDown(opts?: { freeze: boolean }) {
|
||||
this.freezeFrame = opts?.freeze ?? false
|
||||
this.disconnectAll()
|
||||
this.state = {
|
||||
type: EngineConnectionStateType.Disconnecting,
|
||||
@ -996,6 +1002,9 @@ class EngineConnection extends EventTarget {
|
||||
this.pc?.connectionState === 'closed' &&
|
||||
this.unreliableDataChannel?.readyState === 'closed'
|
||||
if (allClosed) {
|
||||
// Do not notify the rest of the program that we have cut off anything.
|
||||
if (this.freezeFrame) return
|
||||
|
||||
this.state = { type: EngineConnectionStateType.Disconnected }
|
||||
}
|
||||
}
|
||||
@ -1619,7 +1628,15 @@ export class EngineCommandManager extends EventTarget {
|
||||
}
|
||||
}
|
||||
tearDown() {
|
||||
this.engineConnection?.tearDown()
|
||||
if (this.engineConnection) {
|
||||
this.engineConnection?.tearDown()
|
||||
// Our window.tearDown assignment causes this case to happen which is
|
||||
// only really for tests.
|
||||
// @ts-ignore
|
||||
} else if (this.engineCommandManager?.engineConnection) {
|
||||
// @ts-ignore
|
||||
this.engineCommandManager?.engineConnection?.tearDown()
|
||||
}
|
||||
}
|
||||
async startNewSession() {
|
||||
this.lastArtifactMap = this.artifactMap
|
||||
|
Reference in New Issue
Block a user