Compare commits
	
		
			5 Commits
		
	
	
		
			nightly-v2
			...
			set-timeou
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 8b5ab06b67 | |||
| 94b606d2d9 | |||
| 2a2cc44baa | |||
| 2d31f5b0e0 | |||
| bb12eec7f9 | 
| @ -1,4 +1,4 @@ | |||||||
| import { useLayoutEffect } from 'react' | import { useRef, useLayoutEffect } from 'react' | ||||||
| import { _executor } from '../lang/executor' | import { _executor } from '../lang/executor' | ||||||
| import { useStore } from '../useStore' | import { useStore } from '../useStore' | ||||||
| import { EngineCommandManager } from '../lang/std/engineConnection' | import { EngineCommandManager } from '../lang/std/engineConnection' | ||||||
| @ -28,6 +28,11 @@ export function useSetupEngineManager( | |||||||
|   const quadWidth = Math.round(width / 4) * 4 |   const quadWidth = Math.round(width / 4) * 4 | ||||||
|   const height = streamHeight ? streamHeight : 0 |   const height = streamHeight ? streamHeight : 0 | ||||||
|   const quadHeight = Math.round(height / 4) * 4 |   const quadHeight = Math.round(height / 4) * 4 | ||||||
|  |   const eng = useRef<{ | ||||||
|  |     engine: EngineCommandManager | ||||||
|  |     width: number | ||||||
|  |     height: number | ||||||
|  |   } | null>(null) | ||||||
|  |  | ||||||
|   useLayoutEffect(() => { |   useLayoutEffect(() => { | ||||||
|     setStreamDimensions({ |     setStreamDimensions({ | ||||||
| @ -35,19 +40,37 @@ export function useSetupEngineManager( | |||||||
|       streamHeight: quadHeight, |       streamHeight: quadHeight, | ||||||
|     }) |     }) | ||||||
|     if (!width || !height) return |     if (!width || !height) return | ||||||
|     const eng = new EngineCommandManager({ |  | ||||||
|       setMediaStream, |     if (eng.current) { | ||||||
|       setIsStreamReady, |       // Before we go further, we're going to check to see if the | ||||||
|       width: quadWidth, |       // width/height is the same as the last go-around. If it is, we | ||||||
|       height: quadHeight, |       // can continue as normal, but if it's different, we should be | ||||||
|       token, |       // clearing out the manager and going again. | ||||||
|     }) |       let c = eng.current | ||||||
|     setEngineCommandManager(eng) |       if (width !== c.width || height !== c.height) { | ||||||
|     eng.waitForReady.then(() => { |         eng.current = null | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (eng.current === null) { | ||||||
|  |       eng.current = { | ||||||
|  |         engine: new EngineCommandManager({ | ||||||
|  |           setMediaStream, | ||||||
|  |           setIsStreamReady, | ||||||
|  |           width: quadWidth, | ||||||
|  |           height: quadHeight, | ||||||
|  |           token, | ||||||
|  |         }), | ||||||
|  |         width: width, | ||||||
|  |         height: height, | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     setEngineCommandManager(eng.current.engine) | ||||||
|  |     eng.current.engine.waitForReady.then(() => { | ||||||
|       executeCode() |       executeCode() | ||||||
|     }) |     }) | ||||||
|     return () => { |     return () => { | ||||||
|       eng?.tearDown() |       eng.current?.engine?.tearDown() | ||||||
|     } |     } | ||||||
|   }, [quadWidth, quadHeight]) |   }, [quadWidth, quadHeight]) | ||||||
| } | } | ||||||
|  | |||||||
| @ -68,12 +68,12 @@ export class EngineConnection { | |||||||
|   constructor({ |   constructor({ | ||||||
|     url, |     url, | ||||||
|     token, |     token, | ||||||
|     onWebsocketOpen = () => {}, |     onWebsocketOpen = () => { }, | ||||||
|     onNewTrack = () => {}, |     onNewTrack = () => { }, | ||||||
|     onEngineConnectionOpen = () => {}, |     onEngineConnectionOpen = () => { }, | ||||||
|     onConnectionStarted = () => {}, |     onConnectionStarted = () => { }, | ||||||
|     onClose = () => {}, |     onClose = () => { }, | ||||||
|     onDataChannelOpen = () => {}, |     onDataChannelOpen = () => { }, | ||||||
|   }: { |   }: { | ||||||
|     url: string |     url: string | ||||||
|     token?: string |     token?: string | ||||||
| @ -364,8 +364,10 @@ export class EngineConnection { | |||||||
|       // fix responsiveness for clients that had a weird network hiccup. |       // fix responsiveness for clients that had a weird network hiccup. | ||||||
|       const connectionTimeoutMs = VITE_KC_CONNECTION_TIMEOUT_MS |       const connectionTimeoutMs = VITE_KC_CONNECTION_TIMEOUT_MS | ||||||
|  |  | ||||||
|  |       console.log('setting timeout for connection') | ||||||
|       setTimeout(() => { |       setTimeout(() => { | ||||||
|         if (this.isReady()) { |         if (this.isReady()) { | ||||||
|  |           console.log('timeout fired but we were ready') | ||||||
|           return |           return | ||||||
|         } |         } | ||||||
|         console.log('engine connection timeout on connection, retrying') |         console.log('engine connection timeout on connection, retrying') | ||||||
| @ -531,8 +533,8 @@ export class EngineCommandManager { | |||||||
|   outSequence = 1 |   outSequence = 1 | ||||||
|   inSequence = 1 |   inSequence = 1 | ||||||
|   engineConnection?: EngineConnection |   engineConnection?: EngineConnection | ||||||
|   waitForReady: Promise<void> = new Promise(() => {}) |   waitForReady: Promise<void> = new Promise(() => { }) | ||||||
|   private resolveReady = () => {} |   private resolveReady = () => { } | ||||||
|  |  | ||||||
|   subscriptions: { |   subscriptions: { | ||||||
|     [event: string]: { |     [event: string]: { | ||||||
| @ -561,6 +563,7 @@ export class EngineCommandManager { | |||||||
|       this.resolveReady = resolve |       this.resolveReady = resolve | ||||||
|     }) |     }) | ||||||
|     const url = `${VITE_KC_API_WS_MODELING_URL}?video_res_width=${width}&video_res_height=${height}` |     const url = `${VITE_KC_API_WS_MODELING_URL}?video_res_width=${width}&video_res_height=${height}` | ||||||
|  |     console.log('new eng conn') | ||||||
|     this.engineConnection = new EngineConnection({ |     this.engineConnection = new EngineConnection({ | ||||||
|       url, |       url, | ||||||
|       token, |       token, | ||||||
| @ -777,7 +780,6 @@ export class EngineCommandManager { | |||||||
|       lastMessage = command.cmd.type |       lastMessage = command.cmd.type | ||||||
|     } |     } | ||||||
|     if (!this.engineConnection?.isReady()) { |     if (!this.engineConnection?.isReady()) { | ||||||
|       console.log('socket not ready') |  | ||||||
|       return Promise.resolve() |       return Promise.resolve() | ||||||
|     } |     } | ||||||
|     if (command.type !== 'modeling_cmd_req') return Promise.resolve() |     if (command.type !== 'modeling_cmd_req') return Promise.resolve() | ||||||
| @ -824,7 +826,6 @@ export class EngineCommandManager { | |||||||
|     this.sourceRangeMap[id] = range |     this.sourceRangeMap[id] = range | ||||||
|  |  | ||||||
|     if (!this.engineConnection?.isReady()) { |     if (!this.engineConnection?.isReady()) { | ||||||
|       console.log('socket not ready') |  | ||||||
|       return Promise.resolve() |       return Promise.resolve() | ||||||
|     } |     } | ||||||
|     this.engineConnection?.send(command) |     this.engineConnection?.send(command) | ||||||
| @ -842,7 +843,7 @@ export class EngineCommandManager { | |||||||
|     command: Models['ModelingCmd_type'], |     command: Models['ModelingCmd_type'], | ||||||
|     range?: SourceRange |     range?: SourceRange | ||||||
|   ) { |   ) { | ||||||
|     let resolve: (val: any) => void = () => {} |     let resolve: (val: any) => void = () => { } | ||||||
|     const promise = new Promise((_resolve, reject) => { |     const promise = new Promise((_resolve, reject) => { | ||||||
|       resolve = _resolve |       resolve = _resolve | ||||||
|     }) |     }) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	