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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // @flow
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { RTCView } from 'react-native-webrtc';
  5. import { Pressable } from '../../../react';
  6. import styles from './styles';
  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. /**
  52. * React Component method that executes once component is mounted.
  53. *
  54. * @inheritdoc
  55. */
  56. componentDidMount() {
  57. // RTCView currently does not support media events, so just fire
  58. // onPlaying callback when <RTCView> is rendered.
  59. const { onPlaying } = this.props;
  60. onPlaying && onPlaying();
  61. }
  62. /**
  63. * Implements React's {@link Component#render()}.
  64. *
  65. * @inheritdoc
  66. * @returns {ReactElement|null}
  67. */
  68. render() {
  69. const { stream } = this.props;
  70. if (stream) {
  71. const streamURL = stream.toURL();
  72. // XXX The CSS style object-fit that we utilize on Web is not
  73. // supported on React Native. Adding objectFit to React Native's
  74. // StyleSheet appears to be impossible without hacking and an
  75. // unjustified amount of effort. Consequently, I've chosen to define
  76. // objectFit on RTCView itself. Anyway, prepare to accommodate a
  77. // future definition of objectFit in React Native's StyleSheet.
  78. const style = styles.video;
  79. const objectFit = (style && style.objectFit) || 'cover';
  80. return (
  81. <Pressable onPress = { this.props.onPress }>
  82. <RTCView
  83. mirror = { this.props.mirror }
  84. objectFit = { objectFit }
  85. streamURL = { streamURL }
  86. style = { style }
  87. zOrder = { this.props.zOrder } />
  88. </Pressable>
  89. );
  90. }
  91. // RTCView has peculiarities which may or may not be platform specific.
  92. // For example, it doesn't accept an empty streamURL. If the execution
  93. // reached here, it means that we explicitly chose to not initialize an
  94. // RTCView as a way of dealing with its idiosyncrasies.
  95. return null;
  96. }
  97. }