You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Video.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* @flow */
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { RTCView } from 'react-native-webrtc';
  5. import styles from './styles';
  6. /**
  7. * The React Native {@link Component} which is similar to Web's
  8. * {@code HTMLVideoElement} and wraps around react-native-webrtc's
  9. * {@link RTCView}.
  10. */
  11. export default class Video extends Component<*> {
  12. /**
  13. * {@code Video} component's property types.
  14. *
  15. * @static
  16. */
  17. static propTypes = {
  18. mirror: PropTypes.bool,
  19. onPlaying: PropTypes.func,
  20. stream: PropTypes.object,
  21. /**
  22. * Similarly to the CSS property z-index, specifies the z-order of this
  23. * Video in the stacking space of all Videos. When Videos overlap,
  24. * zOrder determines which one covers the other. A Video with a larger
  25. * zOrder generally covers a Video with a lower one.
  26. *
  27. * Non-overlapping Videos may safely share a z-order (because one does
  28. * not have to cover the other).
  29. *
  30. * The support for zOrder is platform-dependent and/or
  31. * implementation-specific. Thus, specifying a value for zOrder is to be
  32. * thought of as giving a hint rather than as imposing a requirement.
  33. * For example, video renderers such as Video are commonly implemented
  34. * using OpenGL and OpenGL views may have different numbers of layers in
  35. * their stacking space. Android has three: a layer bellow the window
  36. * (aka default), a layer bellow the window again but above the previous
  37. * layer (aka media overlay), and above the window. Consequently, it is
  38. * advisable to limit the number of utilized layers in the stacking
  39. * space to the minimum sufficient for the desired display. For example,
  40. * a video call application usually needs a maximum of two zOrder
  41. * values: 0 for the remote video(s) which appear in the background, and
  42. * 1 for the local video(s) which appear above the remote video(s).
  43. */
  44. zOrder: PropTypes.number
  45. };
  46. /**
  47. * React Component method that executes once component is mounted.
  48. *
  49. * @inheritdoc
  50. */
  51. componentDidMount() {
  52. // RTCView currently does not support media events, so just fire
  53. // onPlaying callback when <RTCView> is rendered.
  54. const { onPlaying } = this.props;
  55. onPlaying && onPlaying();
  56. }
  57. /**
  58. * Implements React's {@link Component#render()}.
  59. *
  60. * @inheritdoc
  61. * @returns {ReactElement|null}
  62. */
  63. render() {
  64. const { stream } = this.props;
  65. if (stream) {
  66. const streamURL = stream.toURL();
  67. // XXX The CSS style object-fit that we utilize on Web is not
  68. // supported on React Native. Adding objectFit to React Native's
  69. // StyleSheet appears to be impossible without hacking and an
  70. // unjustified amount of effort. Consequently, I've chosen to define
  71. // objectFit on RTCView itself. Anyway, prepare to accommodate a
  72. // future definition of objectFit in React Native's StyleSheet.
  73. const style = styles.video;
  74. const objectFit = (style && style.objectFit) || 'cover';
  75. // eslint-disable-next-line no-extra-parens
  76. return (
  77. <RTCView
  78. mirror = { this.props.mirror }
  79. objectFit = { objectFit }
  80. streamURL = { streamURL }
  81. style = { style }
  82. zOrder = { this.props.zOrder } />
  83. );
  84. }
  85. // RTCView has peculiarities which may or may not be platform specific.
  86. // For example, it doesn't accept an empty streamURL. If the execution
  87. // reached here, it means that we explicitly chose to not initialize an
  88. // RTCView as a way of dealing with its idiosyncrasies.
  89. return null;
  90. }
  91. }