mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-17 23:26:02 +00:00
Fix video queue statistics to poll when on tab
This commit is contained in:
1 parent
27c2bf9b41
commit
7384d5035f
5 files changed
+67
-59
No files matched your search
+11
-1
@@ -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<Props, State> {
|
||||
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<Props, State> {
|
||||
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<Props, State> {
|
||||
case Mode.VIDEO_MODE:
|
||||
component = <VideoComponent
|
||||
currentVideoJob={this.state.currentVideoJob}
|
||||
videoQueuePoller={this.state.videoQueuePoller}
|
||||
videoQueueStats={this.state.videoQueueStats}
|
||||
startVideoJobCallback={this.startVideoJob}
|
||||
updateVideoJobCallback={this.updateVideoJob}
|
||||
updateVideoQueueStatsCallback={this.updateVideoQueueStats}
|
||||
/>
|
||||
break;
|
||||
case Mode.HISTORY_MODE:
|
||||
|
||||
@@ -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<Props, State> {
|
||||
};
|
||||
}
|
||||
|
||||
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<Props, State> {
|
||||
|
||||
<br/>
|
||||
|
||||
<VideoStatsComponent />
|
||||
<div className="content is-size-4">
|
||||
<p>
|
||||
<strong>Queue Length: {this.props.videoQueueStats.queueLength}</strong> (Each takes ~30 seconds.)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{videoResults}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
@@ -1,55 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
interface Props {
|
||||
}
|
||||
|
||||
interface State {
|
||||
queueLength: number,
|
||||
queueHeadPosition: number,
|
||||
queueTailPosition: number,
|
||||
}
|
||||
|
||||
class VideoStatsComponent extends React.Component<Props, State> {
|
||||
|
||||
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 (
|
||||
<div className="content is-size-4">
|
||||
<p>
|
||||
<strong>Queue Length: {queueLength}</strong> (Each takes ~1-5 minutes)
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export { VideoStatsComponent }
|
||||
Reference in new issue
Block a user