refactor(external videos): state as integer

A media state may have more than 2 states. Moving this property back to
integer so it can be extended.
This commit is contained in:
Pedro Beschorner Marin 2021-06-02 15:07:03 -03:00
parent 4a5b92445a
commit d4888f585c
4 changed files with 20 additions and 5 deletions

View File

@ -36,7 +36,7 @@ class UpdateExternalVideoRecordEvent extends AbstractExternalVideoRecordEvent {
eventMap.put(TIME, time.toString)
}
def setState(state: Boolean) {
def setState(state: Int) {
eventMap.put(STATE, state.toString)
}
}

View File

@ -7,7 +7,7 @@ case class StartExternalVideoPubMsgBody(externalVideoUrl: String)
object UpdateExternalVideoPubMsg { val NAME = "UpdateExternalVideoPubMsg" }
case class UpdateExternalVideoPubMsg(header: BbbClientMsgHeader, body: UpdateExternalVideoPubMsgBody) extends StandardMsg
case class UpdateExternalVideoPubMsgBody(status: String, rate: Double, time: Double, state: Boolean)
case class UpdateExternalVideoPubMsgBody(status: String, rate: Double, time: Double, state: Int)
object StopExternalVideoPubMsg { val NAME = "StopExternalVideoPubMsg" }
case class StopExternalVideoPubMsg(header: BbbClientMsgHeader, body: StopExternalVideoPubMsgBody) extends StandardMsg
@ -20,7 +20,7 @@ case class StartExternalVideoEvtMsgBody(externalVideoUrl: String)
object UpdateExternalVideoEvtMsg { val NAME = "UpdateExternalVideoEvtMsg" }
case class UpdateExternalVideoEvtMsg(header: BbbClientMsgHeader, body: UpdateExternalVideoEvtMsgBody) extends BbbCoreMsg
case class UpdateExternalVideoEvtMsgBody(status: String, rate: Double, time: Double, state: Boolean)
case class UpdateExternalVideoEvtMsgBody(status: String, rate: Double, time: Double, state: Int)
object StopExternalVideoEvtMsg { val NAME = "StopExternalVideoEvtMsg" }
case class StopExternalVideoEvtMsg(header: BbbClientMsgHeader, body: StopExternalVideoEvtMsgBody) extends BbbCoreMsg

View File

@ -4,6 +4,7 @@ import { defineMessages, injectIntl } from 'react-intl';
import ReactPlayer from 'react-player';
import { sendMessage, onMessage, removeAllListeners } from './service';
import logger from '/imports/startup/client/logger';
import Service from './service';
import ArcPlayer from './custom-players/arc-player';
import PeerTubePlayer from './custom-players/peertube';
@ -345,8 +346,9 @@ class VideoPlayer extends Component {
this.seekTo(time);
if (playing !== state) {
this.setState({ playing: state });
const playingState = Service.getPlayingState(state);
if (playing !== playingState) {
this.setState({ playing: playingState });
}
});
}

View File

@ -43,6 +43,11 @@ const sendMessage = (event, data) => {
lastMessage = { ...data, event };
// Use an integer for playing state
// 0: stopped 1: playing
// We might use more states in the future
data.state = data.state ? 1 : 0;
makeCall('emitExternalVideoEvent', { status: event, playerStatus: data });
};
@ -64,6 +69,13 @@ const getVideoUrl = () => {
return externalVideo && externalVideo.externalVideoUrl;
};
// Convert state (Number) to playing (Boolean)
const getPlayingState = (state) => {
if (state === 1) return true;
return false;
};
export {
sendMessage,
onMessage,
@ -72,4 +84,5 @@ export {
isUrlValid,
startWatching,
stopWatching,
getPlayingState,
};