Fix up message structure to match the new Engine messages (#316)
* Fix up message structure to match the new Engine messages The types are still jacked up, I reckon we need to bump the node @KittyCAD dep. Signed-off-by: Paul Tagliamonte <paul@kittycad.io> * update types * fmt * export tsc * fmt again --------- Signed-off-by: Paul Tagliamonte <paul@kittycad.io> Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
||||||
"@fortawesome/react-fontawesome": "^0.2.0",
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
||||||
"@headlessui/react": "^1.7.13",
|
"@headlessui/react": "^1.7.13",
|
||||||
"@kittycad/lib": "^0.0.29",
|
"@kittycad/lib": "^0.0.34",
|
||||||
"@react-hook/resize-observer": "^1.2.6",
|
"@react-hook/resize-observer": "^1.2.6",
|
||||||
"@tauri-apps/api": "^1.3.0",
|
"@tauri-apps/api": "^1.3.0",
|
||||||
"@testing-library/jest-dom": "^5.14.1",
|
"@testing-library/jest-dom": "^5.14.1",
|
||||||
|
@ -39,6 +39,7 @@ export const ExportButton = ({ children, className }: ExportButtonProps) => {
|
|||||||
const initialValues: OutputFormat = {
|
const initialValues: OutputFormat = {
|
||||||
type: defaultType,
|
type: defaultType,
|
||||||
storage: 'embedded',
|
storage: 'embedded',
|
||||||
|
presentation: 'compact',
|
||||||
}
|
}
|
||||||
const formik = useFormik({
|
const formik = useFormik({
|
||||||
initialValues,
|
initialValues,
|
||||||
@ -82,6 +83,8 @@ export const ExportButton = ({ children, className }: ExportButtonProps) => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const yo = formik.values
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ActionButton
|
<ActionButton
|
||||||
@ -127,7 +130,9 @@ export const ExportButton = ({ children, className }: ExportButtonProps) => {
|
|||||||
id="storage"
|
id="storage"
|
||||||
name="storage"
|
name="storage"
|
||||||
onChange={formik.handleChange}
|
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"
|
className="bg-chalkboard-20 dark:bg-chalkboard-90 w-full"
|
||||||
>
|
>
|
||||||
{type === 'gltf' && (
|
{type === 'gltf' && (
|
||||||
|
@ -37,11 +37,7 @@ interface NewTrackArgs {
|
|||||||
mediaStream: MediaStream
|
mediaStream: MediaStream
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EngineCommand = Models['WebSocketMessages_type']
|
type WebSocketResponse = Models['OkWebSocketResponseData_type']
|
||||||
|
|
||||||
type OkResponse = Models['OkModelingCmdResponse_type']
|
|
||||||
|
|
||||||
type WebSocketResponse = Models['WebSocketResponses_type']
|
|
||||||
|
|
||||||
// EngineConnection encapsulates the connection(s) to the Engine
|
// EngineConnection encapsulates the connection(s) to the Engine
|
||||||
// for the EngineCommandManager; namely, the underlying WebSocket
|
// for the EngineCommandManager; namely, the underlying WebSocket
|
||||||
@ -158,18 +154,32 @@ export class EngineConnection {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.data.toLocaleLowerCase().startsWith('error')) {
|
const message: Models['WebSocketResponse_type'] = JSON.parse(event.data)
|
||||||
console.error('something went wrong: ', 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
|
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 (this.pc?.signalingState !== 'stable') {
|
||||||
// If the connection is stable, we shouldn't bother updating the
|
// If the connection is stable, we shouldn't bother updating the
|
||||||
// SDP, since we have a stable connection to the backend. If we
|
// SDP, since we have a stable connection to the backend. If we
|
||||||
@ -177,24 +187,26 @@ export class EngineConnection {
|
|||||||
// tore down.
|
// tore down.
|
||||||
this.pc?.setRemoteDescription(
|
this.pc?.setRemoteDescription(
|
||||||
new RTCSessionDescription({
|
new RTCSessionDescription({
|
||||||
type: message.answer.type,
|
type: answer.type,
|
||||||
sdp: message.answer.sdp,
|
sdp: answer.sdp,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (message.type === 'trickle_ice') {
|
} else if (resp.type === 'trickle_ice') {
|
||||||
this.pc?.addIceCandidate(message.candidate as RTCIceCandidateInit)
|
let candidate = resp.data?.candidate
|
||||||
} else if (message.type === 'ice_server_info' && this.pc) {
|
this.pc?.addIceCandidate(candidate as RTCIceCandidateInit)
|
||||||
|
} else if (resp.type === 'ice_server_info' && this.pc) {
|
||||||
console.log('received ice_server_info')
|
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
|
// When we set the Configuration, we want to always force
|
||||||
// iceTransportPolicy to 'relay', since we know the topology
|
// iceTransportPolicy to 'relay', since we know the topology
|
||||||
// of the ICE/STUN/TUN server and the engine. We don't wish to
|
// of the ICE/STUN/TUN server and the engine. We don't wish to
|
||||||
// talk to the engine in any configuration /other/ than relay
|
// talk to the engine in any configuration /other/ than relay
|
||||||
// from a infra POV.
|
// from a infra POV.
|
||||||
this.pc.setConfiguration({
|
this.pc.setConfiguration({
|
||||||
iceServers: message.ice_servers,
|
iceServers: ice_servers,
|
||||||
iceTransportPolicy: 'relay',
|
iceTransportPolicy: 'relay',
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -215,13 +227,7 @@ export class EngineConnection {
|
|||||||
|
|
||||||
this.pc.addEventListener('icecandidate', (event) => {
|
this.pc.addEventListener('icecandidate', (event) => {
|
||||||
if (!this.pc || !this.websocket) return
|
if (!this.pc || !this.websocket) return
|
||||||
if (event.candidate === null) {
|
if (event.candidate !== null) {
|
||||||
// console.log('sent sdp_offer')
|
|
||||||
// this.send({
|
|
||||||
// type: 'sdp_offer',
|
|
||||||
// offer: this.pc.localDescription,
|
|
||||||
// })
|
|
||||||
} else {
|
|
||||||
console.log('sending trickle ice candidate')
|
console.log('sending trickle ice candidate')
|
||||||
const { candidate } = event
|
const { candidate } = event
|
||||||
this.send({
|
this.send({
|
||||||
@ -324,6 +330,8 @@ export class EngineConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type EngineCommand = Models['WebSocketRequest_type']
|
||||||
|
|
||||||
export class EngineCommandManager {
|
export class EngineCommandManager {
|
||||||
artifactMap: ArtifactMap = {}
|
artifactMap: ArtifactMap = {}
|
||||||
sourceRangeMap: SourceRangeMap = {}
|
sourceRangeMap: SourceRangeMap = {}
|
||||||
@ -368,14 +376,16 @@ export class EngineCommandManager {
|
|||||||
let lossyDataChannel = event.channel
|
let lossyDataChannel = event.channel
|
||||||
|
|
||||||
lossyDataChannel.addEventListener('message', (event) => {
|
lossyDataChannel.addEventListener('message', (event) => {
|
||||||
const result: OkResponse = JSON.parse(event.data)
|
const result: Models['OkModelingCmdResponse_type'] = JSON.parse(
|
||||||
|
event.data
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
result.type === 'highlight_set_entity' &&
|
result.type === 'highlight_set_entity' &&
|
||||||
result.sequence &&
|
result?.data?.sequence &&
|
||||||
result.sequence > this.inSequence
|
result.data.sequence > this.inSequence
|
||||||
) {
|
) {
|
||||||
this.onHoverCallback(result.entity_id)
|
this.onHoverCallback(result.data.entity_id)
|
||||||
this.inSequence = result.sequence
|
this.inSequence = result.data.sequence
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -390,15 +400,15 @@ export class EngineCommandManager {
|
|||||||
// Pass this to our export function.
|
// Pass this to our export function.
|
||||||
exportSave(event.data)
|
exportSave(event.data)
|
||||||
} else {
|
} else {
|
||||||
if (event.data.toLocaleLowerCase().startsWith('error')) {
|
const message: Models['WebSocketResponse_type'] = JSON.parse(
|
||||||
// Errors are not JSON encoded; if we have an error we can bail
|
event.data
|
||||||
// here; debugging the error to the console happens in the core
|
)
|
||||||
// engine code.
|
if (
|
||||||
return
|
message.success &&
|
||||||
}
|
message.resp.type === 'modeling' &&
|
||||||
const message: WebSocketResponse = JSON.parse(event.data)
|
message.request_id
|
||||||
if (message.type === 'modeling') {
|
) {
|
||||||
this.handleModelingCommand(message)
|
this.handleModelingCommand(message.resp, message.request_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -418,31 +428,28 @@ export class EngineCommandManager {
|
|||||||
|
|
||||||
this.engineConnection?.connect()
|
this.engineConnection?.connect()
|
||||||
}
|
}
|
||||||
handleModelingCommand(message: WebSocketResponse) {
|
handleModelingCommand(message: WebSocketResponse, id: string) {
|
||||||
if (message.type !== 'modeling') {
|
if (message.type !== 'modeling') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const modelingResponse = message.data.modeling_response
|
||||||
|
|
||||||
const id = message.cmd_id
|
|
||||||
const command = this.artifactMap[id]
|
const command = this.artifactMap[id]
|
||||||
if ('ok' in message.result) {
|
if (modelingResponse.type === 'select_with_point') {
|
||||||
const result: OkResponse = message.result.ok
|
if (modelingResponse?.data?.entity_id) {
|
||||||
if (result.type === 'select_with_point') {
|
|
||||||
if (result.entity_id) {
|
|
||||||
this.onClickCallback({
|
this.onClickCallback({
|
||||||
id: result.entity_id,
|
id: modelingResponse?.data?.entity_id,
|
||||||
type: 'default',
|
type: 'default',
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.onClickCallback()
|
this.onClickCallback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (command && command.type === 'pending') {
|
if (command && command.type === 'pending') {
|
||||||
const resolve = command.resolve
|
const resolve = command.resolve
|
||||||
this.artifactMap[id] = {
|
this.artifactMap[id] = {
|
||||||
type: 'result',
|
type: 'result',
|
||||||
data: message.result,
|
data: modelingResponse,
|
||||||
}
|
}
|
||||||
resolve({
|
resolve({
|
||||||
id,
|
id,
|
||||||
@ -450,7 +457,7 @@ export class EngineCommandManager {
|
|||||||
} else {
|
} else {
|
||||||
this.artifactMap[id] = {
|
this.artifactMap[id] = {
|
||||||
type: 'result',
|
type: 'result',
|
||||||
data: message.result,
|
data: modelingResponse,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1747,10 +1747,10 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60"
|
resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60"
|
||||||
integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==
|
integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==
|
||||||
|
|
||||||
"@kittycad/lib@^0.0.29":
|
"@kittycad/lib@^0.0.34":
|
||||||
version "0.0.29"
|
version "0.0.34"
|
||||||
resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-0.0.29.tgz#e0c0751fc124dd0136f9731c6bb962cd8b8202f6"
|
resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-0.0.34.tgz#c1f1021f6c77bd9f47caa685cfbff0ef358a0316"
|
||||||
integrity sha512-YpyXyOfoUBItJk71AP8M9i4QGvNnNHiSO35dMDx2EsDKqEGwTLDHOBniwPEq+iJqrGcZf2CfBSOvAOnZCH790A==
|
integrity sha512-9pUUuspJB/rayW4adfF7UqRYLw1pugBy3t0+V6qK3sWttG9flgv54fPw3JKewn7VFoEjRtNtoREMAoWb4ZrUIw==
|
||||||
dependencies:
|
dependencies:
|
||||||
node-fetch "3.3.2"
|
node-fetch "3.3.2"
|
||||||
openapi-types "^12.0.0"
|
openapi-types "^12.0.0"
|
||||||
|
Reference in New Issue
Block a user