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

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