Video.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React from 'react';
  2. import {rtcService} from "./services/webrtc";
  3. import {gameService} from "./services/GameService";
  4. export default class Video extends React.Component {
  5. state = {
  6. chatInput: '',
  7. }
  8. componentDidMount() {
  9. rtcService.pageReady();
  10. }
  11. sendChat = () => {
  12. if (this.state.chatInput.length > 0) {
  13. gameService.sendToWs('chat', {message: this.state.chatInput});
  14. this.setState({chatInput: ''});
  15. }
  16. }
  17. chatKeyUp = (e) => {
  18. if (e.keyCode === 13) {
  19. this.sendChat();
  20. }
  21. }
  22. componentDidUpdate(prevProps) {
  23. const messageBody = document.getElementById('chat-box');
  24. messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight;
  25. }
  26. render() {
  27. return (<div className="video-chat">
  28. <h3>Video</h3>
  29. <div className={"video-container remotes"} id={"remotes"}>
  30. <video id="localVideo" autoPlay muted></video>
  31. </div>
  32. <div id="chat-box" className="chat">
  33. {this.props.chat.map((l, index) => <p key={index}>{l}</p>)}
  34. </div>
  35. <div><small><a href="./chat.txt" target="_blank">View full chat</a></small></div>
  36. <div className="chat-input">
  37. <input type="text" value={this.state.chatInput}
  38. placeholder="Text chat here"
  39. onKeyUp={this.chatKeyUp}
  40. onChange={e => this.setState({chatInput: e.target.value})}/>
  41. <button onClick={this.sendChat}>Send</button>
  42. </div>
  43. </div>)
  44. }
  45. }