mirror of
https://github.com/owncast/owncast.git
synced 2024-11-28 11:09:01 +03:00
keep the chat enabled on timer (#1313)
* keep the chat enabled on timer * fix chat deactivation of stream stop * simplify the chat status logic * Use strict inequality Co-authored-by: gingervitis <omqmail@gmail.com> * Use strict inequality Co-authored-by: gingervitis <omqmail@gmail.com> Co-authored-by: gingervitis <omqmail@gmail.com>
This commit is contained in:
parent
af7720a483
commit
4cd7b254da
2 changed files with 38 additions and 22 deletions
|
@ -33,7 +33,7 @@ export default class StandaloneChat extends Component {
|
||||||
accessToken: null,
|
accessToken: null,
|
||||||
username: null,
|
username: null,
|
||||||
isRegistering: false,
|
isRegistering: false,
|
||||||
streamOnline: false, // stream is active/online
|
streamOnline: null, // stream is active/online
|
||||||
lastDisconnectTime: null,
|
lastDisconnectTime: null,
|
||||||
configData: {
|
configData: {
|
||||||
loading: true,
|
loading: true,
|
||||||
|
@ -126,27 +126,36 @@ export default class StandaloneChat extends Component {
|
||||||
}
|
}
|
||||||
const { online, lastDisconnectTime } = status;
|
const { online, lastDisconnectTime } = status;
|
||||||
|
|
||||||
if (status.online && !curStreamOnline) {
|
|
||||||
// stream has just come online.
|
|
||||||
this.handleOnlineMode();
|
|
||||||
} else if (!status.online && curStreamOnline) {
|
|
||||||
// stream has just flipped offline.
|
|
||||||
this.handleOfflineMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
lastDisconnectTime,
|
lastDisconnectTime,
|
||||||
streamOnline: online,
|
streamOnline: online,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (status.online !== curStreamOnline) {
|
||||||
|
if (status.online) {
|
||||||
|
// stream has just come online.
|
||||||
|
this.handleOnlineMode();
|
||||||
|
} else {
|
||||||
|
// stream has just flipped offline or app just got loaded and stream is offline.
|
||||||
|
this.handleOfflineMode(lastDisconnectTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop status timer and disable chat after some time.
|
// stop status timer and disable chat after some time.
|
||||||
handleOfflineMode() {
|
handleOfflineMode(lastDisconnectTime) {
|
||||||
|
if (lastDisconnectTime) {
|
||||||
const remainingChatTime =
|
const remainingChatTime =
|
||||||
TIMER_DISABLE_CHAT_AFTER_OFFLINE -
|
TIMER_DISABLE_CHAT_AFTER_OFFLINE -
|
||||||
(Date.now() - new Date(this.state.lastDisconnectTime));
|
(Date.now() - new Date(lastDisconnectTime));
|
||||||
const countdown = remainingChatTime < 0 ? 0 : remainingChatTime;
|
const countdown = remainingChatTime < 0 ? 0 : remainingChatTime;
|
||||||
|
if (countdown > 0) {
|
||||||
|
this.setState({
|
||||||
|
chatInputEnabled: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.disableChatInputTimer = setTimeout(this.disableChatInput, countdown);
|
this.disableChatInputTimer = setTimeout(this.disableChatInput, countdown);
|
||||||
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
streamOnline: false,
|
streamOnline: false,
|
||||||
});
|
});
|
||||||
|
|
|
@ -76,7 +76,7 @@ export default class App extends Component {
|
||||||
extraPageContent: '',
|
extraPageContent: '',
|
||||||
|
|
||||||
playerActive: false, // player object is active
|
playerActive: false, // player object is active
|
||||||
streamOnline: false, // stream is active/online
|
streamOnline: null, // stream is active/online
|
||||||
isPlaying: false, // player is actively playing video
|
isPlaying: false, // player is actively playing video
|
||||||
|
|
||||||
// status
|
// status
|
||||||
|
@ -259,14 +259,16 @@ export default class App extends Component {
|
||||||
lastDisconnectTime,
|
lastDisconnectTime,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (status.online && !curStreamOnline) {
|
if (status.online !== curStreamOnline) {
|
||||||
|
if (status.online) {
|
||||||
// stream has just come online.
|
// stream has just come online.
|
||||||
this.handleOnlineMode();
|
this.handleOnlineMode();
|
||||||
} else if (!status.online && curStreamOnline) {
|
} else {
|
||||||
// stream has just flipped offline.
|
// stream has just flipped offline or app just got loaded and stream is offline.
|
||||||
this.handleOfflineMode(lastDisconnectTime);
|
this.handleOfflineMode(lastDisconnectTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// when videojs player is ready, start polling for stream
|
// when videojs player is ready, start polling for stream
|
||||||
handlePlayerReady() {
|
handlePlayerReady() {
|
||||||
|
@ -304,6 +306,11 @@ export default class App extends Component {
|
||||||
TIMER_DISABLE_CHAT_AFTER_OFFLINE -
|
TIMER_DISABLE_CHAT_AFTER_OFFLINE -
|
||||||
(Date.now() - new Date(lastDisconnectTime));
|
(Date.now() - new Date(lastDisconnectTime));
|
||||||
const countdown = remainingChatTime < 0 ? 0 : remainingChatTime;
|
const countdown = remainingChatTime < 0 ? 0 : remainingChatTime;
|
||||||
|
if (countdown > 0) {
|
||||||
|
this.setState({
|
||||||
|
chatInputEnabled: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.disableChatInputTimer = setTimeout(this.disableChatInput, countdown);
|
this.disableChatInputTimer = setTimeout(this.disableChatInput, countdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue