Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite the UI using React #3

Merged
merged 19 commits into from
Aug 27, 2020
Merged

Rewrite the UI using React #3

merged 19 commits into from
Aug 27, 2020

Conversation

mrgnr
Copy link
Member

@mrgnr mrgnr commented Aug 22, 2020

React makes it easier to build responsive self-contained components compared to vanilla JavaScript. With React, it should be easier to add new features to the UI in the future.

  • Implement chat room UI components with React
    • Video stage
    • Text message bar
    • Connection info bar
    • Modal to enter username / select devices on entering a room

@mrgnr mrgnr added enhancement New feature or request WIP Work in progress labels Aug 22, 2020
@mrgnr mrgnr marked this pull request as draft August 22, 2020 20:17
The video stage can now display multiple video feeds within a fixed
area. The feeds are layed out to maximize the total area covered within
the video stage. They layout is fully responsive and recomputed any time
the screen is resized or a video feed is added or removed.

The video stage layout uses Flexbox (the video stage has `display: flex`
with `flex-wrap: wrap`). Layout works by first computing how many rows
and columns are needed to include all video feeds. Once the minimum
number of rows and columns is known, a scaling factor is then computed
and applied to calculate the height and width of each video feed. With
the proper scaling factor, the video feeds can simply be added to the
Flexbox and are layed out in the appropriate number of (implicit) rows
and columns.
VideoFeeds only rescale on window resize events or React re-renderings,
so toggling the sidebar would not previously cause VideoFeeds to
rescale. This implementation is not ideal, but works. In the future, it
may be possible to use a Resize Observer to listen for changes in the
dimensions of the VideoStage (see
https://drafts.csswg.org/resize-observer-1/).
Replace the Bootstrap modal that asked for a display name with a modal
implemented in React. The new modal also allows the user to select a
camera and microphone, which was not possible before (devices were
automatically selected).
Users can drag one video feed onto another to swap their locations in
the video stage.
Adding propTypes to each component class allows React to perform type
checking on props in development mode. See
https://reactjs.org/docs/typechecking-with-proptypes.html.
The modal that appears on entering a room creates a new MediaStream
object for the video preview every time a video device is selected. Now
we stop the associated tracks of the MediaStream when another device is
selected and when the component unmounts. This allows the camera to turn
off and prevents having unused tracks running.
Occasionally audio or video would not show up on the other end of the
connection. There were two issues causing this. First, a track might
come in that has no associated stream, so the stream array that comes
with the track is actually empty. We now check for streams[0] before
updating feed.stream, which prevents the <video> srcObject from being
set to undefined. Second, it seems that <video> will refuse to play an
audio track if it is also given a muted video track. This is remedied by
having separate <video> and <audio> elements for each VideoFeed so that
audio will play regardless of what is happening with video.

In a small refactoring, starting and stopping the manager has been moved
from chat.js to App.js.
Previously when a remote video track was stopped, there would remain a
frozen image in the video feed. We now detect when a remote track has
ended by listening for the mute event, then remove the stream from the
corresponding <video> or <audio> element. This prevents the frozen image
and instead displays black when a remote video track has been stopped.
@mrgnr mrgnr removed the WIP Work in progress label Aug 27, 2020
@mrgnr mrgnr changed the title [WIP] Rewrite the UI using React Rewrite the UI using React Aug 27, 2020
@mrgnr mrgnr marked this pull request as ready for review August 27, 2020 09:40
@mrgnr mrgnr merged commit 89bfa17 into master Aug 27, 2020
@mrgnr mrgnr deleted the react branch September 8, 2020 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant