Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

feat(client/plugins): pass router to plugin.register (#7748)

kontrollanten12e5068dfa40
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts
index 016dd64de3..9a1c9f8cd3 100644
--- a/client/src/app/core/plugins/plugin.service.ts
+++ b/client/src/app/core/plugins/plugin.service.ts
@@ -31,6 +31,7 @@ import { firstValueFrom, Observable, of } from 'rxjs'
import { catchError, map, shareReplay } from 'rxjs/operators'
import { environment } from '../../../environments/environment'
import { RegisterClientHelpers } from '../../../types/register-client-option.model'
+import { Router } from '@angular/router'
type FormFields = {
video: {
@@ -50,6 +51,7 @@ export class PluginService implements ClientHook {
private authHttp = inject(HttpClient)
private restExtractor = inject(RestExtractor)
private localeId = inject(LOCALE_ID)
+ private router = inject(Router)
private static BASE_PLUGIN_API_URL = environment.apiUrl + '/api/v1/plugins'
private static BASE_PLUGIN_URL = environment.apiUrl + '/plugins'
@@ -71,11 +73,11 @@ export class PluginService implements ClientHook {
private pluginsManager: PluginsManager
private actions = new Map<ClientDoActionName, ClientDoActionCallback>()
-
constructor () {
this.loadTranslations()
this.pluginsManager = new PluginsManager({
+ router: this.buildRouter(),
doAction: this.doAction.bind(this),
peertubeHelpersFactory: this.buildPeerTubeHelpers.bind(this),
onFormFields: this.onFormFields.bind(this),
@@ -241,6 +243,12 @@ export class PluginService implements ClientHook {
this.clientRoutes[parentRoute][route] = options
}
+ private buildRouter () {
+ return {
+ navigateByUrl: (url: string) => this.router.navigateByUrl(url)
+ }
+ }
+
private buildPeerTubeHelpers (pluginInfo: PluginInfo): RegisterClientHelpers {
const { plugin } = pluginInfo
const npmName = pluginInfo.plugin.npmName
diff --git a/client/src/root-helpers/plugins-manager.ts b/client/src/root-helpers/plugins-manager.ts
index 9de80c3cbb..49d8bf3151 100644
--- a/client/src/root-helpers/plugins-manager.ts
+++ b/client/src/root-helpers/plugins-manager.ts
@@ -4,6 +4,7 @@ import {
ClientDoAction,
ClientHookName,
clientHookObject,
+ ClientRouter,
ClientScriptJSON,
HTMLServerConfig,
PluginClientScope,
@@ -77,6 +78,7 @@ class PluginsManager {
'moderation': new ReplaySubject<boolean>(1)
}
+ private readonly router: ClientRouter
private readonly doAction: ClientDoAction
private readonly peertubeHelpersFactory: PeertubeHelpersFactory
private readonly onFormFields: OnFormFields
@@ -85,6 +87,7 @@ class PluginsManager {
private readonly backendUrl: string
constructor (options: {
+ router?: ClientRouter
doAction?: ClientDoAction
peertubeHelpersFactory: PeertubeHelpersFactory
onFormFields?: OnFormFields
@@ -92,6 +95,7 @@ class PluginsManager {
onClientRoute?: OnClientRoute
backendUrl?: string
}) {
+ this.router = options.router
this.doAction = options.doAction
this.peertubeHelpersFactory = options.peertubeHelpersFactory
this.onFormFields = options.onFormFields
@@ -286,6 +290,7 @@ class PluginsManager {
return dynamicImport(absURL)
.then((script: ClientScript) => {
return script.register({
+ router: this.router,
doAction,
registerHook,
registerVideoField,
diff --git a/client/src/types/register-client-option.model.ts b/client/src/types/register-client-option.model.ts
index 47b8a0e1c6..daa72634f1 100644
--- a/client/src/types/register-client-option.model.ts
+++ b/client/src/types/register-client-option.model.ts
@@ -1,5 +1,6 @@
import {
ClientDoAction,
+ ClientRouter,
MyUser,
RegisterClientFormFieldOptions,
RegisterClientHookOptions,
@@ -10,6 +11,8 @@ import {
} from '@peertube/peertube-models'
export type RegisterClientOptions = {
+ router: ClientRouter
+
doAction: ClientDoAction
registerHook: (options: RegisterClientHookOptions) => void
diff --git a/packages/models/src/plugins/client/index.ts b/packages/models/src/plugins/client/index.ts
index f62a1e8a2f..bf926b4bc1 100644
--- a/packages/models/src/plugins/client/index.ts
+++ b/packages/models/src/plugins/client/index.ts
@@ -7,3 +7,4 @@ export * from './register-client-form-field.model.js'
export * from './register-client-hook.model.js'
export * from './register-client-route.model.js'
export * from './register-client-settings-script.model.js'
+export * from './register-client-router.model.js'
diff --git a/packages/models/src/plugins/client/register-client-router.model.ts b/packages/models/src/plugins/client/register-client-router.model.ts
new file mode 100644
index 0000000000..aae681f52d
--- /dev/null
+++ b/packages/models/src/plugins/client/register-client-router.model.ts
@@ -0,0 +1,4 @@
+
+export type ClientRouter = {
+ navigateByUrl: (url: string) => Promise<boolean>
+}
\ No newline at end of file