Skip to content

Commit

Permalink
fix duplicate engines
Browse files Browse the repository at this point in the history
  • Loading branch information
gonpombo8 committed Jun 27, 2023
1 parent d28ca95 commit e40f5b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/@dcl/inspector/src/hooks/sdk/useSdkContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ export const useSdkContext = () => {
const [catalog] = useCatalog()
const dispatch = useAppDispatch()
let sdkInitialized = false

useEffect(() => {
dispatch(connectDataLayer())
}, [dispatch])

useEffect(() => {
if (!catalog.length || !canvas || !preferences || sdkInitialized) return
if (!catalog.length || !canvas || !preferences || sdkInitialized || !!sdk) return
sdkInitialized = true
createSdkContext(canvas, catalog, preferences)
.then((ctx) => {
Expand Down
13 changes: 4 additions & 9 deletions packages/@dcl/inspector/src/lib/data-layer/host/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function stream(
addUndoCrdt: () => void
): AsyncGenerator<{ data: Uint8Array }> {
const queue = new AsyncQueue<{ data: Uint8Array }>((_) => {})

const engineSerialized = serializeEngine(ctx.engine)
// first we send the fully serialized state over the wire
queue.enqueue({ data: engineSerialized })
Expand All @@ -29,20 +28,16 @@ export function stream(
Object.assign(transport, { name: 'DataLayerHost' })
ctx.engine.addTransport(transport)

async function processMessage(message: Uint8Array) {
function processMessage(message: Uint8Array) {
transport.onmessage!(message)
await ctx.engine.update(1)
void ctx.engine.update(1)
addUndoCrdt()
}

function closeCallback() {
if (!queue.closed) queue.close()
}

// and lastly wire the new messages from the renderer engine
consumeAllMessagesInto(stream, processMessage).catch((err) => {
console.error('x failed: ', err)
closeCallback()
console.error('Faile to consume stream from data layer ', err)
queue.close()
})

// Send initial message (engineSerialized)
Expand Down

0 comments on commit e40f5b5

Please sign in to comment.