Add auth user client hook actions

pull/3888/head
Chocobozzz 2021-03-24 11:34:31 +01:00
parent 2e257e36b7
commit faeec106ef
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 32 additions and 1 deletions

View File

@ -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<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>

View File

@ -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()
},

View File

@ -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<ServerConfig>
notifier: {
info: (text: string, title?: string, timeout?: number) => void,
error: (text: string, title?: string, timeout?: number) => void,

View File

@ -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,