diff --git a/client/src/app/core/plugins/hooks.service.ts b/client/src/app/core/plugins/hooks.service.ts index ec47aa48c..ddde198d2 100644 --- a/client/src/app/core/plugins/hooks.service.ts +++ b/client/src/app/core/plugins/hooks.service.ts @@ -3,13 +3,29 @@ import { mergeMap, switchMap } from 'rxjs/operators' import { Injectable } from '@angular/core' import { PluginService } from '@app/core/plugins/plugin.service' import { ClientActionHookName, ClientFilterHookName, PluginClientScope } from '@shared/models' +import { AuthService, AuthStatus } from '../auth' type RawFunction = (params: U) => T type ObservableFunction = RawFunction> @Injectable() export class HooksService { - constructor (private pluginService: PluginService) { } + constructor ( + private authService: AuthService, + private pluginService: PluginService + ) { + // Run auth hooks + this.authService.userInformationLoaded + .subscribe(() => this.runAction('action:auth-user.information-loaded', 'common', { user: this.authService.getUser() })) + + this.authService.loginChangedSource.subscribe(obj => { + if (obj === AuthStatus.LoggedIn) { + this.runAction('action:auth-user.logged-in', 'common') + } else if (obj === AuthStatus.LoggedOut) { + this.runAction('action:auth-user.logged-out', 'common') + } + }) + } wrapObsFun diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index b755fda2c..54dba5e17 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts @@ -235,6 +235,12 @@ export class PluginService implements ClientHook { .toPromise() }, + getServerConfig: () => { + return this.server.getConfig() + .pipe(catchError(res => this.restExtractor.handleError(res))) + .toPromise() + }, + isLoggedIn: () => { return this.authService.isLoggedIn() }, diff --git a/client/src/types/register-client-option.model.ts b/client/src/types/register-client-option.model.ts index e3c6d803d..7e5356a2b 100644 --- a/client/src/types/register-client-option.model.ts +++ b/client/src/types/register-client-option.model.ts @@ -1,5 +1,6 @@ import { RegisterClientFormFieldOptions, RegisterClientVideoFieldOptions } from '@shared/models/plugins/register-client-form-field.model' import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' +import { ServerConfig } from '@shared/models/server' export type RegisterClientOptions = { registerHook: (options: RegisterClientHookOptions) => void @@ -16,6 +17,8 @@ export type RegisterClientHelpers = { getSettings: () => Promise<{ [ name: string ]: string }> + getServerConfig: () => Promise + notifier: { info: (text: string, title?: string, timeout?: number) => void, error: (text: string, title?: string, timeout?: number) => void, diff --git a/shared/models/plugins/client-hook.model.ts b/shared/models/plugins/client-hook.model.ts index 6c92ef3c6..f8ca32771 100644 --- a/shared/models/plugins/client-hook.model.ts +++ b/shared/models/plugins/client-hook.model.ts @@ -94,6 +94,12 @@ export const clientActionHookObject = { // Fired when the "Go Live" page is being initalized 'action:go-live.init': true, + // Fired when the user explicitely logged in/logged out + 'action:auth-user.logged-in': true, + 'action:auth-user.logged-out': true, + // Fired when the application loaded user information (using tokens from the local storage or after a successful login) + 'action:auth-user.information-loaded': true, + // Fired when the modal to download a video/caption is shown 'action:modal.video-download.shown': true,