From 42b40636991b97fe818007fab19091764fc5db73 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 15 Jul 2022 15:30:14 +0200 Subject: Add ability for client to create server logs --- client/src/standalone/videos/embed-api.ts | 4 ++-- client/src/standalone/videos/embed.ts | 12 +++++++----- client/src/standalone/videos/shared/player-html.ts | 3 ++- .../src/standalone/videos/shared/player-manager-options.ts | 3 ++- client/src/standalone/videos/shared/playlist-fetcher.ts | 5 +++-- client/src/standalone/videos/shared/playlist-tracker.ts | 3 ++- client/src/standalone/videos/shared/video-fetcher.ts | 3 ++- client/src/standalone/videos/test-embed.ts | 11 ++++++----- client/src/standalone/videos/tsconfig.json | 7 +++++++ 9 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 client/src/standalone/videos/tsconfig.json (limited to 'client/src/standalone') diff --git a/client/src/standalone/videos/embed-api.ts b/client/src/standalone/videos/embed-api.ts index 84d664654..2124b4711 100644 --- a/client/src/standalone/videos/embed-api.ts +++ b/client/src/standalone/videos/embed-api.ts @@ -1,6 +1,6 @@ import './embed.scss' - import * as Channel from 'jschannel' +import { logger } from '../../root-helpers' import { PeerTubeResolution, PeerTubeTextTrack } from '../player/definitions' import { PeerTubeEmbed } from './embed' @@ -59,7 +59,7 @@ export class PeerTubeEmbedApi { } private setResolution (resolutionId: number) { - console.log('set resolution %d', resolutionId) + logger.info(`Set resolution ${resolutionId}`) if (this.isWebtorrent()) { if (resolutionId === -1 && this.embed.player.webtorrent().isAutoResolutionPossible() === false) return diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index c15d4db17..5384ada1c 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -6,7 +6,7 @@ import { peertubeTranslate } from '../../../../shared/core-utils/i18n' import { HTMLServerConfig, LiveVideo, ResultList, VideoDetails, VideoPlaylist, VideoPlaylistElement } from '../../../../shared/models' import { PeertubePlayerManager } from '../../assets/player' import { TranslationsManager } from '../../assets/player/translations-manager' -import { getParamString } from '../../root-helpers' +import { getParamString, logger } from '../../root-helpers' import { PeerTubeEmbedApi } from './embed-api' import { AuthHTTP, LiveManager, PeerTubePlugin, PlayerManagerOptions, PlaylistFetcher, PlaylistTracker, VideoFetcher } from './shared' import { PlayerHTML } from './shared/player-html' @@ -31,6 +31,8 @@ export class PeerTubeEmbed { private playlistTracker: PlaylistTracker constructor (videoWrapperId: string) { + logger.registerServerSending(window.location.origin) + this.http = new AuthHTTP() this.videoFetcher = new VideoFetcher(this.http) @@ -43,7 +45,7 @@ export class PeerTubeEmbed { try { this.config = JSON.parse(window['PeerTubeServerConfig']) } catch (err) { - console.error('Cannot parse HTML config.', err) + logger.error('Cannot parse HTML config.', err) } } @@ -125,7 +127,7 @@ export class PeerTubeEmbed { async playNextPlaylistVideo () { const next = this.playlistTracker.getNextPlaylistElement() if (!next) { - console.log('Next element not found in playlist.') + logger.info('Next element not found in playlist.') return } @@ -137,7 +139,7 @@ export class PeerTubeEmbed { async playPreviousPlaylistVideo () { const previous = this.playlistTracker.getPreviousPlaylistElement() if (!previous) { - console.log('Previous element not found in playlist.') + logger.info('Previous element not found in playlist.') return } @@ -343,5 +345,5 @@ PeerTubeEmbed.main() .catch(err => { (window as any).displayIncompatibleBrowser() - console.error('Cannot init embed.', err) + logger.error('Cannot init embed.', err) }) diff --git a/client/src/standalone/videos/shared/player-html.ts b/client/src/standalone/videos/shared/player-html.ts index eb6324ac7..61231d2cb 100644 --- a/client/src/standalone/videos/shared/player-html.ts +++ b/client/src/standalone/videos/shared/player-html.ts @@ -1,5 +1,6 @@ import { peertubeTranslate } from '../../../../../shared/core-utils/i18n' import { VideoDetails } from '../../../../../shared/models' +import { logger } from '../../../root-helpers' import { Translations } from './translations' export class PlayerHTML { @@ -29,7 +30,7 @@ export class PlayerHTML { } displayError (text: string, translations: Translations) { - console.error(text) + logger.error(text) // Remove video element if (this.playerElement) { diff --git a/client/src/standalone/videos/shared/player-manager-options.ts b/client/src/standalone/videos/shared/player-manager-options.ts index f3bd46a69..2eeb5ecac 100644 --- a/client/src/standalone/videos/shared/player-manager-options.ts +++ b/client/src/standalone/videos/shared/player-manager-options.ts @@ -14,6 +14,7 @@ import { getParamString, getParamToggle, isP2PEnabled, + logger, peertubeLocalStorage, UserLocalStorageKeys } from '../../../root-helpers' @@ -137,7 +138,7 @@ export class PlayerManagerOptions { else this.mode = 'webtorrent' } } catch (err) { - console.error('Cannot get params from URL.', err) + logger.error('Cannot get params from URL.', err) } } diff --git a/client/src/standalone/videos/shared/playlist-fetcher.ts b/client/src/standalone/videos/shared/playlist-fetcher.ts index a7e72c177..713d82e3a 100644 --- a/client/src/standalone/videos/shared/playlist-fetcher.ts +++ b/client/src/standalone/videos/shared/playlist-fetcher.ts @@ -1,4 +1,5 @@ import { HttpStatusCode, ResultList, VideoPlaylistElement } from '../../../../../shared/models' +import { logger } from '../../../root-helpers' import { AuthHTTP } from './auth-http' export class PlaylistFetcher { @@ -18,7 +19,7 @@ export class PlaylistFetcher { playlistResponse = await playlistPromise isResponseOk = playlistResponse.status === HttpStatusCode.OK_200 } catch (err) { - console.error(err) + logger.error(err) isResponseOk = false } @@ -49,7 +50,7 @@ export class PlaylistFetcher { } if (i === 10) { - console.error('Cannot fetch all playlists elements, there are too many!') + logger.error('Cannot fetch all playlists elements, there are too many!') } return elements diff --git a/client/src/standalone/videos/shared/playlist-tracker.ts b/client/src/standalone/videos/shared/playlist-tracker.ts index 75d10b4e2..9ea4be83f 100644 --- a/client/src/standalone/videos/shared/playlist-tracker.ts +++ b/client/src/standalone/videos/shared/playlist-tracker.ts @@ -1,4 +1,5 @@ import { VideoPlaylist, VideoPlaylistElement } from '../../../../../shared/models' +import { logger } from '../../../root-helpers' export class PlaylistTracker { private currentPlaylistElement: VideoPlaylistElement @@ -68,7 +69,7 @@ export class PlaylistTracker { setPosition (position: number) { this.currentPlaylistElement = this.playlistElements.find(e => e.position === position) if (!this.currentPlaylistElement || !this.currentPlaylistElement.video) { - console.error('Current playlist element is not valid.', this.currentPlaylistElement) + logger.error('Current playlist element is not valid.', this.currentPlaylistElement) this.currentPlaylistElement = this.getNextPlaylistElement() } diff --git a/client/src/standalone/videos/shared/video-fetcher.ts b/client/src/standalone/videos/shared/video-fetcher.ts index e78d38536..b42d622f9 100644 --- a/client/src/standalone/videos/shared/video-fetcher.ts +++ b/client/src/standalone/videos/shared/video-fetcher.ts @@ -1,4 +1,5 @@ import { HttpStatusCode, LiveVideo, VideoDetails } from '../../../../../shared/models' +import { logger } from '../../../root-helpers' import { AuthHTTP } from './auth-http' export class VideoFetcher { @@ -17,7 +18,7 @@ export class VideoFetcher { videoResponse = await videoPromise isResponseOk = videoResponse.status === HttpStatusCode.OK_200 } catch (err) { - console.error(err) + logger.error(err) isResponseOk = false } diff --git a/client/src/standalone/videos/test-embed.ts b/client/src/standalone/videos/test-embed.ts index 18c338a2d..ab5262902 100644 --- a/client/src/standalone/videos/test-embed.ts +++ b/client/src/standalone/videos/test-embed.ts @@ -1,6 +1,7 @@ import './test-embed.scss' import { PeerTubeResolution, PlayerEventType } from '../player/definitions' import { PeerTubePlayer } from '../player/player' +import { logger } from '../../root-helpers' window.addEventListener('load', async () => { const urlParts = window.location.href.split('/') @@ -20,14 +21,14 @@ window.addEventListener('load', async () => { const mainElement = document.querySelector('#host') mainElement.appendChild(iframe) - console.log('Document finished loading.') + logger.info('Document finished loading.') const player = new PeerTubePlayer(document.querySelector('iframe')) window['player'] = player - console.log('Awaiting player ready...') + logger.info('Awaiting player ready...') await player.ready - console.log('Player is ready.') + logger.info('Player is ready.') const monitoredEvents = [ 'pause', @@ -37,8 +38,8 @@ window.addEventListener('load', async () => { ] monitoredEvents.forEach(e => { - player.addEventListener(e as PlayerEventType, (param) => console.log(`PLAYER: event '${e}' received`, param)) - console.log(`PLAYER: now listening for event '${e}'`) + player.addEventListener(e as PlayerEventType, (param) => logger.info(`PLAYER: event '${e}' received`, { param })) + logger.info(`PLAYER: now listening for event '${e}'`) player.getCurrentPosition() .then(position => { diff --git a/client/src/standalone/videos/tsconfig.json b/client/src/standalone/videos/tsconfig.json new file mode 100644 index 000000000..e0cab7ca3 --- /dev/null +++ b/client/src/standalone/videos/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../tsconfig.json", + "include": [ + "src/standalone/videos/embed.ts", + "src/standalone/videos/test-embed.ts" + ] +} -- cgit v1.2.3