diff --git a/vocodes/src/App.tsx b/vocodes/src/App.tsx index 9ff115bff0..d5b20768b2 100644 --- a/vocodes/src/App.tsx +++ b/vocodes/src/App.tsx @@ -17,6 +17,7 @@ import { VideoComponent } from './modes/video/VideoComponent'; import { VideoJob, VideoJobStatus } from './modes/video/VideoJob'; import { VideoJobPoller } from './modes/video/VideoJobPoller'; import { VideoQueuePoller } from './modes/video/VideoQueuePoller'; +import { VideoQueueStats } from './modes/video/VideoQueueStats'; interface Props { // Certan browsers (iPhone) have pitiful support for drawing APIs. Worse yet, @@ -61,6 +62,7 @@ interface State { // Video Mode State currentVideoJob?: VideoJob, + videoQueueStats: VideoQueueStats, // Dynamic config textCharacterLimit: number, @@ -100,8 +102,9 @@ class App extends React.Component { currentText: '', textCharacterLimit: TEXT_CHARACTER_LIMIT_DEFAULT, currentSpeakerCategory: CATEGORY_ALL, - videoQueuePoller: new VideoQueuePoller(), + videoQueuePoller: new VideoQueuePoller(this.updateVideoQueueStats), videoJobPoller: new VideoJobPoller(this.updateVideoJob), + videoQueueStats: VideoQueueStats.default(), }; } @@ -267,6 +270,10 @@ class App extends React.Component { this.setState({ currentVideoJob: videoJob }); } + updateVideoQueueStats = (videoQueueStats: VideoQueueStats) => { + this.setState({ videoQueueStats: videoQueueStats }); + } + public render() { let component; switch (this.state.mode) { @@ -292,8 +299,11 @@ class App extends React.Component { case Mode.VIDEO_MODE: component = break; case Mode.HISTORY_MODE: diff --git a/vocodes/src/modes/video/VideoComponent.tsx b/vocodes/src/modes/video/VideoComponent.tsx index 6b170eb14f..0f2a5f91c1 100644 --- a/vocodes/src/modes/video/VideoComponent.tsx +++ b/vocodes/src/modes/video/VideoComponent.tsx @@ -1,13 +1,17 @@ import React from 'react'; import { VIDEO_TEMPLATES, VideoTemplate } from './VideoTemplates'; import axios from 'axios'; -import { VideoStatsComponent } from './VideoQueueStatsComponent'; import { VideoJob, VideoJobStatus } from './VideoJob'; +import { VideoQueuePoller } from './VideoQueuePoller'; +import { VideoQueueStats } from './VideoQueueStats'; interface Props { currentVideoJob?: VideoJob, + videoQueueStats: VideoQueueStats, + videoQueuePoller: VideoQueuePoller, startVideoJobCallback: (job: VideoJob) => void, updateVideoJobCallback: (job: VideoJob) => void, + updateVideoQueueStatsCallback: (stats: VideoQueueStats) => void, } interface State { @@ -31,6 +35,14 @@ class VideoComponent extends React.Component { }; } + componentDidMount() { + this.props.videoQueuePoller.start(); + } + + componentWillUnmount() { + this.props.videoQueuePoller.stop(); + } + handleFileChange = (fileList: FileList|null) => { if (fileList === null || fileList === undefined @@ -243,7 +255,11 @@ class VideoComponent extends React.Component {
- +
+

+ Queue Length: {this.props.videoQueueStats.queueLength} (Each takes ~30 seconds.) +

+
{videoResults} diff --git a/vocodes/src/modes/video/VideoQueuePoller.ts b/vocodes/src/modes/video/VideoQueuePoller.ts index e1ed6bb8bb..ea5939fa81 100644 --- a/vocodes/src/modes/video/VideoQueuePoller.ts +++ b/vocodes/src/modes/video/VideoQueuePoller.ts @@ -1,9 +1,14 @@ import { AbstractPoller } from "../../poller/AbstractPoller"; +import { VideoQueueStats } from "./VideoQueueStats"; + class VideoQueuePoller extends AbstractPoller { - constructor() { + updateCallback: (stats: VideoQueueStats) => void; + + constructor(updateCallback: (stats: VideoQueueStats) => void) { super(5000); + this.updateCallback = updateCallback; } performPollAction(): void { @@ -12,6 +17,8 @@ class VideoQueuePoller extends AbstractPoller { .then( (result) => { console.log(result); + let videoQueueStats = VideoQueueStats.fromJson(result); + this.updateCallback(videoQueueStats); } ); } diff --git a/vocodes/src/modes/video/VideoQueueStats.ts b/vocodes/src/modes/video/VideoQueueStats.ts new file mode 100644 index 0000000000..6ed378e701 --- /dev/null +++ b/vocodes/src/modes/video/VideoQueueStats.ts @@ -0,0 +1,30 @@ + +class VideoQueueStats { + queueLength: number; + queueHeadPosition: number; + queueTailPosition: number; + + constructor( + queueLength: number, + queueHeadPosition: number, + queueTailPosition: number + ) { + this.queueLength = queueLength; + this.queueHeadPosition = queueHeadPosition; + this.queueTailPosition = queueTailPosition; + } + + static default() : VideoQueueStats { + return new VideoQueueStats(0, 0, 0); + } + + static fromJson(json: any) : VideoQueueStats { + return new VideoQueueStats( + json.queue_length || 0, + json.queue_head_position || 0, + json.queue_tail_position || 0, + ); + } +} + +export { VideoQueueStats } diff --git a/vocodes/src/modes/video/VideoQueueStatsComponent.tsx b/vocodes/src/modes/video/VideoQueueStatsComponent.tsx deleted file mode 100644 index ce7dc9875c..0000000000 --- a/vocodes/src/modes/video/VideoQueueStatsComponent.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import React from 'react'; - -interface Props { -} - -interface State { - queueLength: number, - queueHeadPosition: number, - queueTailPosition: number, -} - -class VideoStatsComponent extends React.Component { - - constructor(props: Props) { - super(props); - this.state = { - queueLength: 0, - queueHeadPosition: 0, - queueTailPosition: 0, - }; - } - - componentDidMount() { - console.log('component did mount'); - this.pollStats(); - setTimeout(() => this.pollStats(), 5000); - } - - pollStats = () => { - fetch("https://grumble.works/job") - .then(res => res.json()) - .then( - (result) => { - this.setState({ - queueLength: result.queue_length, - queueHeadPosition: result.queue_head_position, - queueTailPosition: result.queue_tail_position, - }) - } - ); - } - - public render() { - let queueLength = this.state.queueLength; - return ( -
-

- Queue Length: {queueLength} (Each takes ~1-5 minutes) -

-
- ) - } -} - -export { VideoStatsComponent }