Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Video.js 4.7KB

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