Skip to content

Commit

Permalink
fix glitch with loading livestream when hitting dashboard page first
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Jun 14, 2023
1 parent ed397b6 commit 6672535
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions ui/src/pages/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Dashboard extends React.Component {
currentRecording: '',
initialised: false,
};
this.initialiseLiveview = this.initialiseLiveview.bind(this);
}

componentDidMount() {
Expand All @@ -48,30 +49,11 @@ class Dashboard extends React.Component {
});
});
}
this.initialiseLiveview();
}

componentDidUpdate() {
const { initialised } = this.state;
if (!initialised) {
const { connected, dispatchSend } = this.props;
const message = {
message_type: 'stream-sd',
};
if (connected) {
dispatchSend(message);
}

const requestStreamInterval = interval(2000);
this.requestStreamSubscription = requestStreamInterval.subscribe(() => {
if (connected) {
dispatchSend(message);
}
});

this.setState({
initialised: true,
});
}
this.initialiseLiveview();
}

componentWillUnmount() {
Expand Down Expand Up @@ -101,6 +83,30 @@ class Dashboard extends React.Component {
return Math.round(Date.now() / 1000);
}

initialiseLiveview() {
const { initialised } = this.state;
if (!initialised) {
const message = {
message_type: 'stream-sd',
};
const { connected, dispatchSend } = this.props;
if (connected) {
dispatchSend(message);
}

const requestStreamInterval = interval(2000);
this.requestStreamSubscription = requestStreamInterval.subscribe(() => {
const { connected: isConnected } = this.props;
if (isConnected) {
dispatchSend(message);
}
});
this.setState({
initialised: true,
});
}
}

openModal(file) {
this.setState({
open: true,
Expand Down

0 comments on commit 6672535

Please sign in to comment.