From c43ed8e8624383db5a0cf22b210cee202bae323c Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Mon, 10 Oct 2022 15:18:31 +0200 Subject: Expose PeerTube socket to plugins (#5239) * server(pluginHelpers): add socket * test(plugins): add socket cases * fixes after review * Update plugin-helpers.ts * Update plugin-helpers.ts --- server/lib/plugins/plugin-helpers-builder.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'server/lib/plugins') diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts index 4e799b3d4..35945422c 100644 --- a/server/lib/plugins/plugin-helpers-builder.ts +++ b/server/lib/plugins/plugin-helpers-builder.ts @@ -13,13 +13,14 @@ import { ServerBlocklistModel } from '@server/models/server/server-blocklist' import { UserModel } from '@server/models/user/user' import { VideoModel } from '@server/models/video/video' import { VideoBlacklistModel } from '@server/models/video/video-blacklist' -import { MPlugin } from '@server/types/models' +import { MPlugin, MVideo, UserNotificationModelForApi } from '@server/types/models' import { PeerTubeHelpers } from '@server/types/plugins' import { VideoBlacklistCreate, VideoStorage } from '@shared/models' import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' import { ServerConfigManager } from '../server-config-manager' import { blacklistVideo, unblacklistVideo } from '../video-blacklist' import { VideoPathManager } from '../video-path-manager' +import { PeerTubeSocket } from '../peertube-socket' function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { const logger = buildPluginLogger(npmName) @@ -35,6 +36,8 @@ function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHel const plugin = buildPluginRelatedHelpers(pluginModel, npmName) + const socket = buildSocketHelpers() + const user = buildUserHelpers() return { @@ -45,6 +48,7 @@ function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHel moderation, plugin, server, + socket, user } } @@ -218,6 +222,17 @@ function buildPluginRelatedHelpers (plugin: MPlugin, npmName: string) { } } +function buildSocketHelpers () { + return { + sendNotification: (userId: number, notification: UserNotificationModelForApi) => { + PeerTubeSocket.Instance.sendNotification(userId, notification) + }, + sendVideoLiveNewState: (video: MVideo) => { + PeerTubeSocket.Instance.sendVideoLiveNewState(video) + } + } +} + function buildUserHelpers () { return { loadById: (id: number) => { -- cgit v1.2.3