Skip to content

Commit

Permalink
Fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirox committed Sep 6, 2023
1 parent c823af5 commit 49333bc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/bit-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ export const MediaContentBounds = defineComponent({
bounds: [Types.f32, 3]
});
export const MediaInfo = defineComponent({
accessibleUrl: Types.ui32
accessibleUrl: Types.ui32,
contentType: Types.ui32
});
MediaInfo.accessibleUrl[$isStringType] = true;
MediaInfo.contentType[$isStringType] = true;

export const SceneRoot = defineComponent();
export const NavMesh = defineComponent();
Expand Down
1 change: 1 addition & 0 deletions src/bit-systems/media-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ function* loadMedia(world: HubsWorld, eid: EntityID) {
addComponent(world, MediaLoaded, media);
addComponent(world, MediaInfo, media);
MediaInfo.accessibleUrl[media] = APP.getSid(urlData.accessibleUrl);
MediaInfo.contentType[media] = APP.getSid(urlData.contentType);
} catch (e) {
console.error(e);
media = renderAsEntity(world, ErrorObject());
Expand Down
6 changes: 3 additions & 3 deletions src/react-components/room/hooks/useObjectList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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 { mediaSort, mediaSortAframe, getMediaType, getMediaTypeAframe } from "../../../utils/media-sorting.js";
import { shouldUseNewLoader } from "../../../utils/bit-utils";
import { defineQuery } from "bitecs";
import { MediaInfo } from "../../../bit-components.js";
Expand Down Expand Up @@ -90,12 +90,12 @@ export function ObjectListProvider({ scene, children }) {
}));
setObjects(objects);
} else {
const objects = scene.systems["listed-media"].els.sort(mediaSort).map(el => ({
const objects = scene.systems["listed-media"].els.sort(mediaSortAframe).map(el => ({
id: el.object3D.id,
// Having a listed-media component does not guarantee the existence of a media-loader component,
// so don't crash if there isn't one.
name: getDisplayString((el.components["media-loader"] && el.components["media-loader"].data.src) || ""),
type: getMediaType(el),
type: getMediaTypeAframe(el),
el
}));
setObjects(objects);
Expand Down
23 changes: 12 additions & 11 deletions src/utils/media-sorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { faNewspaper } from "@fortawesome/free-solid-svg-icons/faNewspaper";
import { faQuestion } from "@fortawesome/free-solid-svg-icons/faQuestion";
import { faCube } from "@fortawesome/free-solid-svg-icons/faCube";
import { hasComponent } from "bitecs";
import { GLTFModel, MediaImage, MediaPDF, MediaVideo } from "../bit-components";
import { GLTFModel, MediaImage, MediaInfo, MediaPDF, MediaVideo } from "../bit-components";

export const SORT_ORDER_VIDEO = 0;
export const SORT_ORDER_AUDIO = 1;
Expand All @@ -15,18 +15,19 @@ export const SORT_ORDER_MODEL = 4;
export const SORT_ORDER_UNIDENTIFIED = 5;

function mediaSortOrder(eid) {
if (hasComponent(APP.world, MediaVideo)) {
const contentTypeSid = MediaVideo.contentType[eid];
const contentType = APP.getString(contentTypeSid);
if (contentType.startsWith("audio/")) {
return SORT_ORDER_AUDIO;
} else {
return SORT_ORDER_VIDEO;
if (hasComponent(APP.world, MediaVideo, eid)) {
if (hasComponent(APP.world, MediaInfo, eid)) {
const contentTypeSid = MediaInfo.contentType[eid];
const contentType = APP.getString(contentTypeSid);
if (contentType.startsWith("audio/")) {
return SORT_ORDER_AUDIO;
}
}
return SORT_ORDER_VIDEO;
}
if (hasComponent(APP.world, MediaImage)) return SORT_ORDER_IMAGE;
if (hasComponent(APP.world, MediaPDF)) return SORT_ORDER_PDF;
if (hasComponent(APP.world, GLTFModel)) return SORT_ORDER_MODEL;
if (hasComponent(APP.world, MediaImage, eid)) return SORT_ORDER_IMAGE;
if (hasComponent(APP.world, MediaPDF, eid)) return SORT_ORDER_PDF;
if (hasComponent(APP.world, GLTFModel, eid)) return SORT_ORDER_MODEL;
return SORT_ORDER_UNIDENTIFIED;
}

Expand Down

0 comments on commit 49333bc

Please sign in to comment.