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

Video.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { RTCView } from 'react-native-webrtc';
  4. import { Pressable } from '../../../react';
  5. import VideoTransform from './VideoTransform';
  6. import styles from './styles';
  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 below the window
  33. * (aka default), a layer below 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. var avt_style = this.props.avt_style || {}
  73. clog("avt_style:",avt_style)
  74. if (stream) {
  75. // RTCView
  76. const style = styles.video;
  77. // const objectFit
  78. var objectFit
  79. = zoomEnabled
  80. ? 'contain'
  81. : (style && style.objectFit) || 'cover';
  82. // var video_info = window.glob_vhook.fns.glob_dev_fncb ? window.glob_vhook.fns.glob_dev_fncb("video_info",{that:this,vc:{objectFit,style}},0) : {}
  83. var video_info = window.gvx.fns.fncb ? gvx.fns.fncb("video_info",{that:this,vc:{objectFit,style,vct:1}},0) : {}
  84. const rtcView
  85. = (
  86. <RTCView
  87. mirror = { this.props.mirror }
  88. objectFit = { objectFit }
  89. streamURL = { stream.toURL() }
  90. style = { {...style,...avt_style} }
  91. zOrder = { this.props.zOrder } />
  92. );
  93. // VideoTransform implements "pinch to zoom". As part of "pinch to
  94. // zoom", it implements onPress, of course.
  95. if (zoomEnabled) {
  96. return (
  97. <VideoTransform
  98. enabled = { zoomEnabled }
  99. onPress = { onPress }
  100. streamId = { stream.id }
  101. style = { {...style,...avt_style} }>
  102. { rtcView }
  103. </VideoTransform>
  104. );
  105. }
  106. // XXX Unfortunately, VideoTransform implements a custom press
  107. // detection which has been observed to be very picky about the
  108. // precision of the press unlike the builtin/default/standard press
  109. // detection which is forgiving to imperceptible movements while
  110. // pressing. It's not acceptable to be so picky, especially when
  111. // "pinch to zoom" is not enabled.
  112. return (
  113. <Pressable onPress = { onPress }>
  114. { rtcView }
  115. </Pressable>
  116. );
  117. }
  118. // RTCView has peculiarities which may or may not be platform specific.
  119. // For example, it doesn't accept an empty streamURL. If the execution
  120. // reached here, it means that we explicitly chose to not initialize an
  121. // RTCView as a way of dealing with its idiosyncrasies.
  122. return null;
  123. }
  124. }