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 4.0KB

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