aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins
diff options
context:
space:
mode:
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>2022-10-10 15:18:31 +0200
committerGitHub <noreply@github.com>2022-10-10 15:18:31 +0200
commitc43ed8e8624383db5a0cf22b210cee202bae323c (patch)
treed2d2c3d06a0b15048bf1e1893b2bc8d07ed2214d /server/lib/plugins
parent213bb3bb58b719679d533811b2e2c3852a3dd067 (diff)
downloadPeerTube-c43ed8e8624383db5a0cf22b210cee202bae323c.tar.gz
PeerTube-c43ed8e8624383db5a0cf22b210cee202bae323c.tar.zst
PeerTube-c43ed8e8624383db5a0cf22b210cee202bae323c.zip
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
Diffstat (limited to 'server/lib/plugins')
-rw-r--r--server/lib/plugins/plugin-helpers-builder.ts17
1 files changed, 16 insertions, 1 deletions
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'
13import { UserModel } from '@server/models/user/user' 13import { UserModel } from '@server/models/user/user'
14import { VideoModel } from '@server/models/video/video' 14import { VideoModel } from '@server/models/video/video'
15import { VideoBlacklistModel } from '@server/models/video/video-blacklist' 15import { VideoBlacklistModel } from '@server/models/video/video-blacklist'
16import { MPlugin } from '@server/types/models' 16import { MPlugin, MVideo, UserNotificationModelForApi } from '@server/types/models'
17import { PeerTubeHelpers } from '@server/types/plugins' 17import { PeerTubeHelpers } from '@server/types/plugins'
18import { VideoBlacklistCreate, VideoStorage } from '@shared/models' 18import { VideoBlacklistCreate, VideoStorage } from '@shared/models'
19import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' 19import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist'
20import { ServerConfigManager } from '../server-config-manager' 20import { ServerConfigManager } from '../server-config-manager'
21import { blacklistVideo, unblacklistVideo } from '../video-blacklist' 21import { blacklistVideo, unblacklistVideo } from '../video-blacklist'
22import { VideoPathManager } from '../video-path-manager' 22import { VideoPathManager } from '../video-path-manager'
23import { PeerTubeSocket } from '../peertube-socket'
23 24
24function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { 25function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers {
25 const logger = buildPluginLogger(npmName) 26 const logger = buildPluginLogger(npmName)
@@ -35,6 +36,8 @@ function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHel
35 36
36 const plugin = buildPluginRelatedHelpers(pluginModel, npmName) 37 const plugin = buildPluginRelatedHelpers(pluginModel, npmName)
37 38
39 const socket = buildSocketHelpers()
40
38 const user = buildUserHelpers() 41 const user = buildUserHelpers()
39 42
40 return { 43 return {
@@ -45,6 +48,7 @@ function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHel
45 moderation, 48 moderation,
46 plugin, 49 plugin,
47 server, 50 server,
51 socket,
48 user 52 user
49 } 53 }
50} 54}
@@ -218,6 +222,17 @@ function buildPluginRelatedHelpers (plugin: MPlugin, npmName: string) {
218 } 222 }
219} 223}
220 224
225function buildSocketHelpers () {
226 return {
227 sendNotification: (userId: number, notification: UserNotificationModelForApi) => {
228 PeerTubeSocket.Instance.sendNotification(userId, notification)
229 },
230 sendVideoLiveNewState: (video: MVideo) => {
231 PeerTubeSocket.Instance.sendVideoLiveNewState(video)
232 }
233 }
234}
235
221function buildUserHelpers () { 236function buildUserHelpers () {
222 return { 237 return {
223 loadById: (id: number) => { 238 loadById: (id: number) => {