diff --git a/shared/js/main.tsx b/shared/js/main.tsx index 6a6e7af8..2abacd47 100644 --- a/shared/js/main.tsx +++ b/shared/js/main.tsx @@ -27,6 +27,11 @@ import {server_connections} from "tc-shared/ConnectionManager"; import {spawnConnectModalNew} from "tc-shared/ui/modal/connect/Controller"; import {initializeKeyControl} from "./KeyControl"; import {assertMainApplication} from "tc-shared/ui/utils"; +import {clientServiceInvite} from "tc-shared/clientservice"; +import {ActionResult} from "tc-services"; +import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration"; +import {ErrorCode} from "tc-shared/connection/ErrorCode"; +import {bookmarks} from "tc-shared/Bookmarks"; /* required import for init */ import "svg-sprites/client-icons"; @@ -49,11 +54,7 @@ import "./ui/elements/ContextDivider"; import "./ui/elements/Tab"; import "./clientservice"; import "./text/bbcode/InviteController"; -import {clientServiceInvite} from "tc-shared/clientservice"; -import {ActionResult} from "tc-services"; -import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration"; -import {ErrorCode} from "tc-shared/connection/ErrorCode"; -import {bookmarks} from "tc-shared/Bookmarks"; +import "./text/bbcode/YoutubeController"; assertMainApplication(); diff --git a/shared/js/text/bbcode/InviteController.ts b/shared/js/text/bbcode/InviteController.ts index 3482c7f0..7b7a9862 100644 --- a/shared/js/text/bbcode/InviteController.ts +++ b/shared/js/text/bbcode/InviteController.ts @@ -5,6 +5,9 @@ import {IpcInviteInfo} from "tc-shared/text/bbcode/InviteDefinitions"; import {LogCategory, logError} from "tc-shared/log"; import {clientServiceInvite, clientServices} from "tc-shared/clientservice"; import {handleConnectRequest} from "tc-shared/main"; +import {assertMainApplication} from "tc-shared/ui/utils"; + +assertMainApplication(); let ipcChannel: IPCChannel; loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, { diff --git a/shared/js/text/bbcode/InviteRenderer.tsx b/shared/js/text/bbcode/InviteRenderer.tsx index df5f20f1..504d83a7 100644 --- a/shared/js/text/bbcode/InviteRenderer.tsx +++ b/shared/js/text/bbcode/InviteRenderer.tsx @@ -2,7 +2,6 @@ import * as React from "react"; import {IpcInviteInfo, IpcInviteInfoLoaded} from "tc-shared/text/bbcode/InviteDefinitions"; import {ChannelMessage, getIpcInstance, IPCChannel} from "tc-shared/ipc/BrowserIPC"; import * as loader from "tc-loader"; -import {AppParameters} from "tc-shared/settings"; import {useEffect, useState} from "react"; import _ = require("lodash"); import {Translatable} from "tc-shared/ui/react-elements/i18n"; diff --git a/shared/js/text/bbcode/YoutubeController.ts b/shared/js/text/bbcode/YoutubeController.ts new file mode 100644 index 00000000..63fbb0e5 --- /dev/null +++ b/shared/js/text/bbcode/YoutubeController.ts @@ -0,0 +1,26 @@ +import {ChannelMessage, getIpcInstance, IPCChannel} from "tc-shared/ipc/BrowserIPC"; +import * as loader from "tc-loader"; +import {global_client_actions} from "tc-shared/events/GlobalEvents"; +import {assertMainApplication} from "tc-shared/ui/utils"; + +assertMainApplication(); + +let ipcChannel: IPCChannel; +loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, { + name: "Invite controller init", + function: async () => { + ipcChannel = getIpcInstance().createChannel("bbcode-youtube"); + ipcChannel.messageHandler = handleIpcMessage; + }, + priority: 10 +}); + + +function handleIpcMessage(remoteId: string, broadcast: boolean, message: ChannelMessage) { + if(message.type === "bbcode-youtube") { + global_client_actions.fire("action_w2g", { + videoUrl: message.data.videoUrl, + handlerId: message.data.handlerId + }); + } +} \ No newline at end of file diff --git a/shared/js/text/bbcode/youtube.scss b/shared/js/text/bbcode/YoutubeRenderer.scss similarity index 100% rename from shared/js/text/bbcode/youtube.scss rename to shared/js/text/bbcode/YoutubeRenderer.scss diff --git a/shared/js/text/bbcode/youtube.tsx b/shared/js/text/bbcode/YoutubeRenderer.tsx similarity index 81% rename from shared/js/text/bbcode/youtube.tsx rename to shared/js/text/bbcode/YoutubeRenderer.tsx index 2b3ee28a..9e04d784 100644 --- a/shared/js/text/bbcode/youtube.tsx +++ b/shared/js/text/bbcode/YoutubeRenderer.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as loader from "tc-loader"; -import {rendererReact, rendererText} from "tc-shared/text/bbcode/renderer"; +import {BBCodeHandlerContext, rendererReact, rendererText} from "tc-shared/text/bbcode/renderer"; import {ElementRenderer} from "vendor/xbbcode/renderer/base"; import {TagElement} from "vendor/xbbcode/elements"; import {BBCodeRenderer} from "tc-shared/text/bbcode"; @@ -8,11 +8,11 @@ import {HTMLRenderer} from "tc-shared/ui/react-elements/HTMLRenderer"; import * as contextmenu from "tc-shared/ui/elements/ContextMenu"; import {spawn_context_menu} from "tc-shared/ui/elements/ContextMenu"; import {copyToClipboard} from "tc-shared/utils/helpers"; -import {global_client_actions} from "tc-shared/events/GlobalEvents"; -import {server_connections} from "tc-shared/ConnectionManager"; +import {getIpcInstance, IPCChannel} from "tc-shared/ipc/BrowserIPC"; +import {useContext} from "react"; const playIcon = require("./yt-play-button.svg"); -const cssStyle = require("./youtube.scss"); +const cssStyle = require("./YoutubeRenderer.scss"); const patternYtVideoId = /^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^?&"'>]{10,11})$/; let reactId = 0; @@ -36,6 +36,8 @@ export const YoutubeRenderer = (props: { children?: React.ReactElement | React.R } } + const handlerId = useContext(BBCodeHandlerContext); + return (