您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Video.js 5.0KB

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