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<U, T> = (params: U) => T
type ObservableFunction<U, T> = RawFunction<U, Observable<T>>
@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
<P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName>
.toPromise()
},
+ getServerConfig: () => {
+ return this.server.getConfig()
+ .pipe(catchError(res => this.restExtractor.handleError(res)))
+ .toPromise()
+ },
+
isLoggedIn: () => {
return this.authService.isLoggedIn()
},
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
getSettings: () => Promise<{ [ name: string ]: string }>
+ getServerConfig: () => Promise<ServerConfig>
+
notifier: {
info: (text: string, title?: string, timeout?: number) => void,
error: (text: string, title?: string, timeout?: number) => void,
// 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,