Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import styles from './main_screen';
  3.  
  4. export default class ConferenceMainScreen extends React.Component {
  5.  
  6.   constructor(props) {
  7.     super(props);
  8.     this.state = {
  9.       participants: []
  10.     }
  11.   }
  12.  
  13.   componentWillMount() {
  14.     this.localStream = Erizo.Stream({audio: true, video: true, data: false});
  15.     this.room = Erizo.Room({token: this.props.roomToken});
  16.   }
  17.  
  18.   componentDidMount() {
  19.     this.init();
  20.     this.localStream.init();
  21.   }
  22.  
  23.   init() {
  24.     this.localStream.addEventListener("access-accepted", () => {
  25.       this.whenConnected();
  26.       this.whenSubscribedToStreams();
  27.       this.whenAddedAStream();
  28.       this.room.connect();
  29.       this.localStream.play("main-screen");
  30.     });
  31.   }
  32.  
  33.   whenConnected() {
  34.     this.room.addEventListener("room-connected", (roomEvent) => {
  35.       this.room.publish(this.localStream);
  36.       this.subscribeToStreams(roomEvent.streams);
  37.     });
  38.   }
  39.  
  40.   whenSubscribedToStreams() {
  41.     this.room.addEventListener("stream-subscribed", (streamEvent) => {
  42.       const participants = this.state.participants;
  43.       participants.push(streamEvent);
  44.       this.setState({ participants }, () => {
  45.         this.state.participants.forEach((participant, key) => {
  46.           const stream = participant.stream;
  47.           stream.play(`participant-${stream}`);
  48.         });
  49.       });
  50.     });
  51.   }
  52.  
  53.   whenAddedAStream() {
  54.     this.room.addEventListener("stream-added", (streamEvent) => {
  55.       const streams = [];
  56.       streams.push(streamEvent.stream);
  57.       this.subscribeToStreams(streams);
  58.     });
  59.   }
  60.  
  61.   whenAStreamIsRemoved() {
  62.     this.room.addEventListener("stream-removed", (streamEvent) => {
  63.       const stream = streamEvent.stream;
  64.       if (stream.elementID !== undefined) {
  65.  
  66.       }
  67.     });
  68.   }
  69.  
  70.   subscribeToStreams(streams = []) {
  71.     streams.forEach(stream => {
  72.       if (stream.getID() !== this.localStream.getID()) {
  73.         this.room.subscribe(stream);
  74.       }
  75.     });
  76.   };
  77.  
  78.   renderParticipants() {
  79.     return this.state.participants.map((participant, key) => {
  80.       return(
  81.         <div id={`participant-${participant.stream.getID()}`} key={key} className={styles.participantsPanel.participants}></div>
  82.       );
  83.     });
  84.   }
  85.  
  86.   render() {
  87.     return(
  88.       <div id="main-screen" className={styles.mainScreen}>
  89.         <div className={styles.participantsPanel}>
  90.           {this.renderParticipants()}
  91.         </div>
  92.       </div>
  93.     );
  94.   }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement