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

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