Compare commits

...

1 Commits

Author SHA1 Message Date
cbca63c6e0 WIP: Start synchronizing the enableSketchMode call 2025-02-21 16:57:36 -06:00
2 changed files with 83 additions and 21 deletions

View File

@ -1335,21 +1335,34 @@ export async function letEngineAnimateAndSyncCamAfter(
engineCommandManager: EngineCommandManager, engineCommandManager: EngineCommandManager,
entityId: string entityId: string
) { ) {
await engineCommandManager.sendSceneCommand({ const enableSketchCmdId = uuidv4()
type: 'modeling_cmd_req', console.warn('ADAM: enableSketchMode promise has ID', enableSketchCmdId)
cmd_id: uuidv4(), await engineCommandManager.sendSceneCommand(
cmd: { {
type: 'enable_sketch_mode', type: 'modeling_cmd_req',
adjust_camera: true, cmd_id: enableSketchCmdId,
animated: !isReducedMotion(), cmd: {
ortho: true, type: 'enable_sketch_mode',
entity_id: entityId, adjust_camera: true,
animated: !isReducedMotion(),
ortho: true,
entity_id: entityId,
},
}, },
}) false,
// wait 600ms (animation takes 500, + 100 for safety) // Callback triggers when the enable_sketch_mode finishes successfully.
await new Promise((resolve) => (_whatever) => {
setTimeout(resolve, isReducedMotion() ? 100 : 600) console.error('ADAM: Hello from the resolvedCb')
window.alert("G'day ADAM and Frank, enable_sketch_mode is done")
},
// Callback triggers when the enable_sketch_mode fails.
(_whatever) => {
console.error('ADAM: Hello from the rejectCb')
window.alert("G'day ADAM and Frank, enable_sketch_mode is FUCKING TOAST")
}
) )
// TODO: Wait for one of the two callbacks above to finish.
await engineCommandManager.sendSceneCommand({ await engineCommandManager.sendSceneCommand({
// CameraControls subscribes to default_camera_get_settings response events // CameraControls subscribes to default_camera_get_settings response events
// firing this at connection ensure the camera's are synced initially // firing this at connection ensure the camera's are synced initially

View File

@ -440,7 +440,9 @@ class EngineConnection extends EventTarget {
this.tearDown = () => {} this.tearDown = () => {}
this.websocket.addEventListener('open', this.onWebSocketOpen) this.websocket.addEventListener('open', this.onWebSocketOpen)
// Is this listener ever even used???
this.websocket?.addEventListener('message', ((event: MessageEvent) => { this.websocket?.addEventListener('message', ((event: MessageEvent) => {
console.log('ADAM: Received a message')
const message: Models['WebSocketResponse_type'] = JSON.parse(event.data) const message: Models['WebSocketResponse_type'] = JSON.parse(event.data)
const pending = const pending =
this.engineCommandManager.pendingCommands[message.request_id || ''] this.engineCommandManager.pendingCommands[message.request_id || '']
@ -450,6 +452,7 @@ class EngineConnection extends EventTarget {
// If there's no body to the response, we can bail here. // If there's no body to the response, we can bail here.
if (!resp || !resp.type) { if (!resp || !resp.type) {
console.log('ADAM: Resolved an empty-body promise', message.request_id)
return return
} }
@ -509,6 +512,8 @@ class EngineConnection extends EventTarget {
) )
} }
// ADAM: Is this where resolved promises go?
console.log('ADAM: Resolved some promise', message.request_id)
pending.resolve([message]) pending.resolve([message])
delete this.engineCommandManager.pendingCommands[message.request_id || ''] delete this.engineCommandManager.pendingCommands[message.request_id || '']
}) as EventListener) }) as EventListener)
@ -674,7 +679,7 @@ class EngineConnection extends EventTarget {
this.onIceCandidateError = (_event: Event) => { this.onIceCandidateError = (_event: Event) => {
const event = _event as RTCPeerConnectionIceErrorEvent const event = _event as RTCPeerConnectionIceErrorEvent
console.warn( console.log(
`ICE candidate returned an error: ${event.errorCode}: ${event.errorText} for ${event.url}` `ICE candidate returned an error: ${event.errorCode}: ${event.errorText} for ${event.url}`
) )
} }
@ -1022,12 +1027,18 @@ class EngineConnection extends EventTarget {
event.data event.data
) )
console.log('ADAM: Got msg', message.request_id, 'type', message)
if (!message.success) { if (!message.success) {
const pending =
this.engineCommandManager.pendingCommands[
message.request_id || ''
]
const errorsString = message?.errors const errorsString = message?.errors
?.map((error) => { ?.map((error) => {
return ` - ${error.error_code}: ${error.message}` return ` - ${error.error_code}: ${error.message}`
}) })
.join('\n') .join('\n')
pending.reject(errorsString)
if (message.request_id) { if (message.request_id) {
const artifactThatFailed = const artifactThatFailed =
this.engineCommandManager.artifactGraph.get(message.request_id) this.engineCommandManager.artifactGraph.get(message.request_id)
@ -1070,8 +1081,23 @@ class EngineConnection extends EventTarget {
let resp = message.resp let resp = message.resp
const pending =
this.engineCommandManager.pendingCommands[message.request_id || '']
console.log(
'ADAM: Successful response to ',
message.request_id,
pending
)
if (pending !== undefined) {
console.warn('ADAM: Resolving!')
pending.resolve([message])
pending.promise.then((p) => {
console.log('ADAM: Found a promise.then')
})
}
// If there's no body to the response, we can bail here. // If there's no body to the response, we can bail here.
if (!resp || !resp.type) { if (!resp || !resp.type) {
console.log('ADAM: Bailing because empty')
return return
} }
@ -1082,6 +1108,7 @@ class EngineConnection extends EventTarget {
case 'modeling_session_data': case 'modeling_session_data':
let api_call_id = resp.data?.session?.api_call_id let api_call_id = resp.data?.session?.api_call_id
console.log('ADAM: ')
console.log(`API Call ID: ${api_call_id}`) console.log(`API Call ID: ${api_call_id}`)
break break
@ -1103,7 +1130,7 @@ class EngineConnection extends EventTarget {
// No ICE servers can be valid in a local dev. env. // No ICE servers can be valid in a local dev. env.
if (ice_servers?.length === 0) { if (ice_servers?.length === 0) {
console.warn('No ICE servers') console.log('No ICE servers')
this.pc?.setConfiguration({ this.pc?.setConfiguration({
bundlePolicy: 'max-bundle', bundlePolicy: 'max-bundle',
}) })
@ -1410,7 +1437,7 @@ export class EngineCommandManager extends EventTarget {
height: number = 1337 height: number = 1337
/** /**
* Export intent traxcks the intent of the export. If it is null there is no * Export intent tracks the intent of the export. If it is null there is no
* export in progress. Otherwise it is an enum value of the intent. * export in progress. Otherwise it is an enum value of the intent.
* Another export cannot be started if one is already in progress. * Another export cannot be started if one is already in progress.
*/ */
@ -1683,7 +1710,7 @@ export class EngineCommandManager extends EventTarget {
} }
case ExportIntent.Make: { case ExportIntent.Make: {
if (!this.machineManager) { if (!this.machineManager) {
console.warn('Some how, no manufacturing machine is selected.') console.log('Some how, no manufacturing machine is selected.')
break break
} }
@ -1944,7 +1971,9 @@ export class EngineCommandManager extends EventTarget {
} }
sendSceneCommand( sendSceneCommand(
command: EngineCommand, command: EngineCommand,
forceWebsocket = false forceWebsocket = false,
resolveCb?: (value: any | PromiseLike<any>) => void,
rejectCb?: (value: any | PromiseLike<any>) => void
): Promise<Models['WebSocketResponse_type'] | null> { ): Promise<Models['WebSocketResponse_type'] | null> {
if (this.engineConnection === undefined) { if (this.engineConnection === undefined) {
return Promise.resolve(null) return Promise.resolve(null)
@ -2053,7 +2082,9 @@ export class EngineCommandManager extends EventTarget {
idToRangeMap: {}, idToRangeMap: {},
range: defaultSourceRange(), range: defaultSourceRange(),
}, },
true // isSceneCommand true, // isSceneCommand
resolveCb,
rejectCb
) )
.then(([a]) => a) .then(([a]) => a)
.catch((e) => { .catch((e) => {
@ -2111,9 +2142,16 @@ export class EngineCommandManager extends EventTarget {
range: PendingMessage['range'] range: PendingMessage['range']
idToRangeMap: PendingMessage['idToRangeMap'] idToRangeMap: PendingMessage['idToRangeMap']
}, },
isSceneCommand = false isSceneCommand = false,
resolveCb?: (value: any | PromiseLike<any>) => void,
rejectCb?: (value: any | PromiseLike<any>) => void
): Promise<[Models['WebSocketResponse_type']]> { ): Promise<[Models['WebSocketResponse_type']]> {
const { promise, resolve, reject } = promiseFactory<any>() const { promise, resolve, reject } = (() => {
if (resolveCb === undefined) return promiseFactory<any>()
if (rejectCb === undefined) return promiseFactory<any>()
return promiseFactoryFor(resolveCb, rejectCb)
})()
// console.log('ADAM:', resolveCb, promise)
this.pendingCommands[id] = { this.pendingCommands[id] = {
resolve, resolve,
reject, reject,
@ -2269,3 +2307,14 @@ function promiseFactory<T>() {
}) })
return { promise, resolve, reject } return { promise, resolve, reject }
} }
function promiseFactoryFor<T>(
resolve: (value: T | PromiseLike<T>) => void,
reject: (value: T | PromiseLike<T>) => void
) {
const promise = new Promise<T>((_resolve, _reject) => {
resolve = _resolve
reject = _reject
})
return { promise, resolve, reject }
}