Skip to content

Commit

Permalink
fix: unify to entity.id the scene_id by comms, remove unused kernel c…
Browse files Browse the repository at this point in the history
…ode (#6156)
  • Loading branch information
leanmendoza authored Apr 9, 2024
1 parent 049d0e3 commit 9aa4fec
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function registerCommunicationsControllerServiceServerImplementation(port
* The `receiveCommsMessage` relays messages in direction: scene -> comms
*/
const commsController: ICommunicationsController = {
cid: ctx.sceneData.id,
cid: ctx.sceneData.entity.id || ctx.sceneData.id,
receiveCommsMessage(preData: Uint8Array, sender: PeerInformation) {
const [msgType, data] = decodeMessage(preData)
if (msgType === MsgType.String) {
Expand Down Expand Up @@ -85,13 +85,13 @@ export function registerCommunicationsControllerServiceServerImplementation(port
return {
async send(req, ctx) {
const message = textEncoder.encode(req.message)
sendParcelSceneCommsMessage(ctx.sceneData.id, encodeMessage(message, MsgType.String))
sendParcelSceneCommsMessage(commsController.cid, encodeMessage(message, MsgType.String))
return {}
},
async sendBinary(req, ctx) {
// Send messages
for (const data of req.data) {
sendParcelSceneCommsMessage(ctx.sceneData.id, encodeMessage(data, MsgType.Uint8Array))
sendParcelSceneCommsMessage(commsController.cid, encodeMessage(data, MsgType.Uint8Array))
}

// Process received messages
Expand Down
15 changes: 0 additions & 15 deletions browser-interface/packages/shared/comms/sceneSubscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,3 @@ export function subscribeParcelSceneToCommsMessages(controller: ICommunicationsC
export function unsubscribeParcelSceneToCommsMessages(controller: ICommunicationsController) {
scenesSubscribedToCommsEvents.delete(controller)
}

/**
* Retrieve the scene IDs that are subscribed to receive scene messages from comms
*
* @returns a list of CIDs, identifying the Scenes by their hash
*/
export function getParcelSceneSubscriptions(): string[] {
const ids: string[] = []

scenesSubscribedToCommsEvents.forEach(($) => {
ids.push($.cid)
})

return ids
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class EmptyParcelController {
id: entityId,
baseUrl: this.baseUrl + 'contents/',
entity: {
id: entityId,
content: emptyScenes[sceneName]!,
pointers: [coordinates],
timestamp: Date.now(),
Expand Down
2 changes: 1 addition & 1 deletion browser-interface/packages/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export type SceneSourcePlacement = {
export const VOICE_CHAT_FEATURE_TOGGLE: SceneFeatureToggle = { name: 'voiceChat', default: 'enabled' }

export type LoadableScene = {
readonly entity: Readonly<Omit<Entity, 'id'>>
readonly entity: Readonly<Entity>
readonly baseUrl: string
readonly id: string
/** Id of the parent scene that spawned this scene experience */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ export async function wearableToSceneEntity(wearable: WearableV2, defaultBaseUrl
baseUrl,
parentCid: 'avatar',
entity: {
// TODO: the wearable.id is an urn because the wearable was fetched
// from `lambdas/wearables` instead of `content/entities/active`
id: wearable.id,
content,
metadata,
pointers: [wearable.id],
Expand Down
1 change: 1 addition & 0 deletions browser-interface/packages/unity-interface/dcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async function startGlobalScene(cid: string, title: string, fileContentUrl: stri
id: cid,
baseUrl,
entity: {
id: cid,
content: [...extraContent, { file: 'scene.js', hash: fileContentUrl }],
pointers: [cid],
timestamp: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export async function getPortableExperienceFromUrn(sceneUrn: string): Promise<Lo

const result = await fetch(resolvedUrl)
const entity = (await result.json()) as Entity
if (!entity.id) {
entity.id = resolvedEntity.cid
}

const baseUrl: string = resolvedEntity.baseUrl || new URL('.', resolvedUrl).toString()

return {
Expand Down
1 change: 1 addition & 0 deletions browser-interface/test/unit/RestrictedActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ describe('RestrictedActions tests', () => {
sceneNumber: 3,
baseUrl: '',
entity: {
id: 'test',
version: 'v3',
content: [],
pointers: [],
Expand Down
1 change: 1 addition & 0 deletions browser-interface/test/unit/portableExperiences.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Portable experiences sagas test', () => {
id: urn,
baseUrl: '',
entity: {
id: urn,
content: [],
metadata: {
menuBarIcon: 'icon'
Expand Down

0 comments on commit 9aa4fec

Please sign in to comment.