Skip to content

Commit

Permalink
fix(app): fix LP media embed not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenlx committed Jan 26, 2024
1 parent 43833f8 commit 9c94ea2
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions apps/app/src/patch/embed-widget/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import type { EditorView } from "@codemirror/view";
import { WidgetType } from "@codemirror/view";
import { Platform } from "obsidian";
import type { MediaViewState } from "@/components/context";
import { dataLpPassthrough } from "@/components/player/buttons";
import { encodeWebpageUrl } from "@/lib/remote-player/encode";
import { parseSizeSyntax } from "@/lib/size-syntax";
import type { UrlMediaInfo } from "@/media-note/note-index/url-info";
import { MediaRenderChild } from "@/media-view/url-embed";
import type MediaExtended from "@/mx-main";

type InfoFacet = Partial<Pick<MediaViewState, "source" | "hash">>;

class UrlMediaRenderChild extends MediaRenderChild {
constructor(public containerEl: HTMLElement, public plugin: MediaExtended) {
super(containerEl, plugin);
Expand Down Expand Up @@ -123,10 +126,7 @@ abstract class UrlPlayerWidget extends WidgetType {
);
}

abstract toInfoFacet(media: UrlMediaInfo): Partial<{
hash: string;
src: string;
}>;
abstract toInfoFacet(media: UrlMediaInfo): InfoFacet;

setDOM(view: EditorView, container: HTMLDivElement) {
container.tabIndex = -1;
Expand Down Expand Up @@ -202,37 +202,53 @@ Object.defineProperty(UrlPlayerWidget.prototype, "estimatedHeight", {
});

export class VideoUrlPlayerWidget extends UrlPlayerWidget {
toInfoFacet(media: UrlMediaInfo): Partial<{ hash: string; src: string }> {
toInfoFacet(media: UrlMediaInfo): InfoFacet {
return {
hash: media.hash,
src: media.source.href,
source: {
src: media.source.href,
original: media.original,
viewType: media.viewType,
},
};
}
}

export class AudioUrlPlayerWidget extends UrlPlayerWidget {
toInfoFacet(media: UrlMediaInfo): Partial<{ hash: string; src: string }> {
toInfoFacet(media: UrlMediaInfo): InfoFacet {
return {
hash: media.hash,
src: media.source.href,
source: {
src: media.source.href,
original: media.original,
viewType: media.viewType,
},
};
}
}

export class IframePlayerWidget extends UrlPlayerWidget {
toInfoFacet(media: UrlMediaInfo): Partial<{ hash: string; src: string }> {
toInfoFacet(media: UrlMediaInfo): InfoFacet {
return {
hash: media.hash,
src: media.source.href,
source: {
src: media.source.href,
original: media.original,
viewType: media.viewType,
},
};
}
}

export class WebpagePlayerWidget extends UrlPlayerWidget {
toInfoFacet(media: UrlMediaInfo): Partial<{ hash: string; src: string }> {
toInfoFacet(media: UrlMediaInfo): InfoFacet {
return {
hash: media.hash,
src: encodeWebpageUrl(media.source.href),
source: {
src: encodeWebpageUrl(media.source.href),
original: media.original,
viewType: media.viewType,
},
};
}
}
Expand Down

0 comments on commit 9c94ea2

Please sign in to comment.