diff --git a/package.json b/package.json index 8f0d83f19..1bad30d16 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@fortawesome/free-solid-svg-icons": "^6.4.2", "@fortawesome/react-fontawesome": "^0.2.0", "@headlessui/react": "^1.7.13", - "@kittycad/lib": "^0.0.29", + "@kittycad/lib": "^0.0.34", "@react-hook/resize-observer": "^1.2.6", "@tauri-apps/api": "^1.3.0", "@testing-library/jest-dom": "^5.14.1", diff --git a/src/components/ExportButton.tsx b/src/components/ExportButton.tsx index e074d8b67..4e26bb57a 100644 --- a/src/components/ExportButton.tsx +++ b/src/components/ExportButton.tsx @@ -39,6 +39,7 @@ export const ExportButton = ({ children, className }: ExportButtonProps) => { const initialValues: OutputFormat = { type: defaultType, storage: 'embedded', + presentation: 'compact', } const formik = useFormik({ initialValues, @@ -82,6 +83,8 @@ export const ExportButton = ({ children, className }: ExportButtonProps) => { }, }) + const yo = formik.values + return ( <> { id="storage" name="storage" onChange={formik.handleChange} - value={formik.values.storage} + value={ + 'storage' in formik.values ? formik.values.storage : '' + } className="bg-chalkboard-20 dark:bg-chalkboard-90 w-full" > {type === 'gltf' && ( diff --git a/src/lang/std/engineConnection.ts b/src/lang/std/engineConnection.ts index bafce6f5a..eaa5d268d 100644 --- a/src/lang/std/engineConnection.ts +++ b/src/lang/std/engineConnection.ts @@ -37,11 +37,7 @@ interface NewTrackArgs { mediaStream: MediaStream } -export type EngineCommand = Models['WebSocketMessages_type'] - -type OkResponse = Models['OkModelingCmdResponse_type'] - -type WebSocketResponse = Models['WebSocketResponses_type'] +type WebSocketResponse = Models['OkWebSocketResponseData_type'] // EngineConnection encapsulates the connection(s) to the Engine // for the EngineCommandManager; namely, the underlying WebSocket @@ -158,18 +154,32 @@ export class EngineConnection { return } - if (event.data.toLocaleLowerCase().startsWith('error')) { - console.error('something went wrong: ', event.data) + const message: Models['WebSocketResponse_type'] = JSON.parse(event.data) + + if (!message.success) { + if (message.request_id) { + console.error(`Error in response to request ${message.request_id}:`) + } else { + console.error(`Error from server:`) + } + message.errors.forEach((error) => { + console.error(` - ${error.error_code}: ${error.message}`) + }) return } - const message: WebSocketResponse = JSON.parse(event.data) + let resp = message.resp + if (!resp) { + // If there's no body to the response, we can bail here. + return + } + + if (resp.type === 'sdp_answer') { + let answer = resp.data?.answer + if (!answer || answer.type === 'unspecified') { + return + } - if ( - message.type === 'sdp_answer' && - message?.answer && - message?.answer?.type !== 'unspecified' - ) { if (this.pc?.signalingState !== 'stable') { // If the connection is stable, we shouldn't bother updating the // SDP, since we have a stable connection to the backend. If we @@ -177,24 +187,26 @@ export class EngineConnection { // tore down. this.pc?.setRemoteDescription( new RTCSessionDescription({ - type: message.answer.type, - sdp: message.answer.sdp, + type: answer.type, + sdp: answer.sdp, }) ) } - } else if (message.type === 'trickle_ice') { - this.pc?.addIceCandidate(message.candidate as RTCIceCandidateInit) - } else if (message.type === 'ice_server_info' && this.pc) { + } else if (resp.type === 'trickle_ice') { + let candidate = resp.data?.candidate + this.pc?.addIceCandidate(candidate as RTCIceCandidateInit) + } else if (resp.type === 'ice_server_info' && this.pc) { console.log('received ice_server_info') + let ice_servers = resp.data?.ice_servers - if (message?.ice_servers?.length > 0) { + if (ice_servers?.length > 0) { // When we set the Configuration, we want to always force // iceTransportPolicy to 'relay', since we know the topology // of the ICE/STUN/TUN server and the engine. We don't wish to // talk to the engine in any configuration /other/ than relay // from a infra POV. this.pc.setConfiguration({ - iceServers: message.ice_servers, + iceServers: ice_servers, iceTransportPolicy: 'relay', }) } else { @@ -215,13 +227,7 @@ export class EngineConnection { this.pc.addEventListener('icecandidate', (event) => { if (!this.pc || !this.websocket) return - if (event.candidate === null) { - // console.log('sent sdp_offer') - // this.send({ - // type: 'sdp_offer', - // offer: this.pc.localDescription, - // }) - } else { + if (event.candidate !== null) { console.log('sending trickle ice candidate') const { candidate } = event this.send({ @@ -324,6 +330,8 @@ export class EngineConnection { } } +export type EngineCommand = Models['WebSocketRequest_type'] + export class EngineCommandManager { artifactMap: ArtifactMap = {} sourceRangeMap: SourceRangeMap = {} @@ -368,14 +376,16 @@ export class EngineCommandManager { let lossyDataChannel = event.channel lossyDataChannel.addEventListener('message', (event) => { - const result: OkResponse = JSON.parse(event.data) + const result: Models['OkModelingCmdResponse_type'] = JSON.parse( + event.data + ) if ( result.type === 'highlight_set_entity' && - result.sequence && - result.sequence > this.inSequence + result?.data?.sequence && + result.data.sequence > this.inSequence ) { - this.onHoverCallback(result.entity_id) - this.inSequence = result.sequence + this.onHoverCallback(result.data.entity_id) + this.inSequence = result.data.sequence } }) }) @@ -390,15 +400,15 @@ export class EngineCommandManager { // Pass this to our export function. exportSave(event.data) } else { - if (event.data.toLocaleLowerCase().startsWith('error')) { - // Errors are not JSON encoded; if we have an error we can bail - // here; debugging the error to the console happens in the core - // engine code. - return - } - const message: WebSocketResponse = JSON.parse(event.data) - if (message.type === 'modeling') { - this.handleModelingCommand(message) + const message: Models['WebSocketResponse_type'] = JSON.parse( + event.data + ) + if ( + message.success && + message.resp.type === 'modeling' && + message.request_id + ) { + this.handleModelingCommand(message.resp, message.request_id) } } }) @@ -418,31 +428,28 @@ export class EngineCommandManager { this.engineConnection?.connect() } - handleModelingCommand(message: WebSocketResponse) { + handleModelingCommand(message: WebSocketResponse, id: string) { if (message.type !== 'modeling') { return } + const modelingResponse = message.data.modeling_response - const id = message.cmd_id const command = this.artifactMap[id] - if ('ok' in message.result) { - const result: OkResponse = message.result.ok - if (result.type === 'select_with_point') { - if (result.entity_id) { - this.onClickCallback({ - id: result.entity_id, - type: 'default', - }) - } else { - this.onClickCallback() - } + if (modelingResponse.type === 'select_with_point') { + if (modelingResponse?.data?.entity_id) { + this.onClickCallback({ + id: modelingResponse?.data?.entity_id, + type: 'default', + }) + } else { + this.onClickCallback() } } if (command && command.type === 'pending') { const resolve = command.resolve this.artifactMap[id] = { type: 'result', - data: message.result, + data: modelingResponse, } resolve({ id, @@ -450,7 +457,7 @@ export class EngineCommandManager { } else { this.artifactMap[id] = { type: 'result', - data: message.result, + data: modelingResponse, } } } diff --git a/yarn.lock b/yarn.lock index ff074d0bc..9e2f97ab7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1747,10 +1747,10 @@ resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60" integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA== -"@kittycad/lib@^0.0.29": - version "0.0.29" - resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-0.0.29.tgz#e0c0751fc124dd0136f9731c6bb962cd8b8202f6" - integrity sha512-YpyXyOfoUBItJk71AP8M9i4QGvNnNHiSO35dMDx2EsDKqEGwTLDHOBniwPEq+iJqrGcZf2CfBSOvAOnZCH790A== +"@kittycad/lib@^0.0.34": + version "0.0.34" + resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-0.0.34.tgz#c1f1021f6c77bd9f47caa685cfbff0ef358a0316" + integrity sha512-9pUUuspJB/rayW4adfF7UqRYLw1pugBy3t0+V6qK3sWttG9flgv54fPw3JKewn7VFoEjRtNtoREMAoWb4ZrUIw== dependencies: node-fetch "3.3.2" openapi-types "^12.0.0"