Skip to content

Commit

Permalink
Move media info to its own component
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and takahirox committed Sep 1, 2023
1 parent fc9e988 commit 972868d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/bit-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ export const LoadedByMediaLoader = defineComponent();
export const MediaContentBounds = defineComponent({
bounds: [Types.f32, 3]
});
export const MediaInfo = defineComponent({
accessibleUrl: Types.ui32,
canonicalUrl: Types.ui32,
canonicalAudioUrl: Types.ui32,
contentType: Types.ui32,
mediaType: Types.ui8,
thumbnail: Types.ui32
});

export const SceneRoot = defineComponent();
export const NavMesh = defineComponent();
Expand Down
11 changes: 7 additions & 4 deletions src/bit-systems/media-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GLTFModel,
LoadedByMediaLoader,
MediaContentBounds,
MediaInfo,
MediaLoaded,
MediaLoader,
Networked,
Expand Down Expand Up @@ -207,10 +208,12 @@ function* loadMedia(world: HubsWorld, eid: EntityID) {
}
media = yield* loader(world, eid, urlData);
addComponent(world, MediaLoaded, media);
const srcSid = APP.getSid(urlData.accessibleUrl);
MediaLoaded.src[media] = srcSid;
const contentTypeSid = APP.getSid(urlData.contentType);
MediaLoaded.contentType[media] = contentTypeSid;
MediaInfo.accessibleUrl[media] = APP.getSid(urlData.accessibleUrl);
MediaInfo.canonicalUrl[media] = APP.getSid(urlData.canonicalUrl);
urlData.canonicalAudioUrl && (MediaInfo.canonicalAudioUrl[media] = APP.getSid(urlData.canonicalAudioUrl));
MediaInfo.contentType[media] = APP.getSid(urlData.contentType);
urlData.mediaType && (MediaInfo.mediaType[media] = urlData.mediaType);
addComponent(world, MediaInfo, media);
} catch (e) {
console.error(e);
media = renderAsEntity(world, ErrorObject());
Expand Down
6 changes: 4 additions & 2 deletions src/react-components/room/hooks/useObjectList.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useState, useEffect, useContext, createContext, useCallback, Children, cloneElement } from "react";
import PropTypes from "prop-types";
import { mediaSort, getMediaType } from "../../../utils/media-sorting.js";
import { defineQuery } from "bitecs";
import { MediaInfo } from "../../../bit-components.js";

function getDisplayString(elOrEid) {
let url;
if (!elOrEid.isEntity) {
const srcSid = MediaLoaded.src[elOrEid];
const srcSid = MediaInfo.accessibleUrl[elOrEid];
url = APP.getString(srcSid);
} else {
// Having a listed-media component does not guarantee the existence of a media-loader component,
Expand Down Expand Up @@ -74,7 +76,7 @@ function handleDeselect(scene, object, callback) {
}
}

const queryListedMedia = defineQuery([MediaLoaded]);
const queryListedMedia = defineQuery([MediaInfo]);
export function ObjectListProvider({ scene, children }) {
const [objects, setObjects] = useState([]);
const [focusedObject, setFocusedObject] = useState(null); // The object currently shown in the viewport
Expand Down
4 changes: 2 additions & 2 deletions src/react-components/room/object-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { rotateInPlaceAroundWorldUp, affixToWorldUp } from "../../utils/three-ut
import { getPromotionTokenForFile } from "../../utils/media-utils";
import { hasComponent } from "bitecs";
import { isPinned as getPinnedState } from "../../bit-systems/networking";
import { MediaLoaded, Pinnable, Pinned, Static } from "../../bit-components";
import { MediaInfo, MediaLoaded, Pinnable, Pinned, Static } from "../../bit-components";
import { deleteTheDeletableAncestor } from "../../bit-systems/delete-entity-system";

export function isMe(object) {
Expand All @@ -27,7 +27,7 @@ export function getObjectUrl(object) {
url =
mediaLoader && ((mediaLoader.data.mediaOptions && mediaLoader.data.mediaOptions.href) || mediaLoader.data.src);
} else {
const urlSid = MediaLoaded.src[object.el];
const urlSid = MediaInfo.accessibleUrl[object.el];
url = APP.getString(urlSid);
}

Expand Down

0 comments on commit 972868d

Please sign in to comment.