time sync

This commit is contained in:
Ayushya Amitabh
2020-05-03 16:02:04 -04:00
parent 2e6d943b9e
commit 8aef416eda
6 changed files with 100 additions and 108 deletions
+13 -19
View File
@@ -54,6 +54,7 @@ export default class Chat extends Component {
this.gifClick = this.gifClick.bind(this);
}
componentDidMount() {
// EVENT CAPTURE FOR ENTER TO SEND
window.onkeypress = (ev) => {
if (ev.code === 'Enter') {
if (ev.target === document.getElementById('chat-message-box-input')) {
@@ -65,11 +66,18 @@ export default class Chat extends Component {
}
}
};
// VIDEO LISTENER START
this.mVideoListener.start();
// CHROME FIREBASE FIRESTORE LISTENER
this.port = chrome.runtime.connect({ name: window.localStorage.getItem('watchPartyRoomId') });
// Initialize listener
this.port.postMessage({
type: 'INIT',
roomId: window.localStorage.getItem('watchPartyRoomId'),
});
// Listener
this.port.onMessage.addListener((response) => {
if (response.isError === true) {
this.props.notify('Uh oh. Got lost from the party.');
@@ -77,31 +85,17 @@ export default class Chat extends Component {
return;
}
this.setState(response);
if (response.player && this.state.localPlayer.status !== response.player.status) {
if (response.player.source !== getPlayerSource()) {
this.props.updateLoading(true);
this.props.notify('This party is for a different website');
goTo(Create, this.props);
this.props.updateLoading(false);
} else {
if (this.mVideoListener.isUpdating === false)
this.mVideoListener.doUpdate(response.player);
}
}
if (response.player) this.mVideoListener.doUpdate(response.player);
const pcc = document.getElementsByClassName('thread-container')[0];
if (pcc) pcc.scrollTop = pcc.scrollHeight;
});
this.mVideoListener.start();
// DONE WITH MOUNTING TASKS
this.props.updateLoading(false);
}
videoEventListener(video) {
this.setState({ localPlayer: video });
if (
this.state.player.status !== video.status &&
video.showName &&
video.status !== PLAYER_STATUS.NOT_PLAYING
)
this.syncPlayer(video);
this.syncPlayer(video);
}
syncPlayer(video) {
const { status, showName, time, source, element } = video;
@@ -190,7 +184,7 @@ export default class Chat extends Component {
});
}
sendMessageInvoker(overrideMessage) {
if (overrideMessage) console.log(overrideMessage);
if (overrideMessage) this.sendMessage(overrideMessage);
else {
const trim = this.state.newMessage.replace(/^\s+|\s+$/g, '');
if (trim !== '') this.sendMessage(trim);