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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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:>",window.is_var_exist,window.is_var_exist2,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,stream,zoomEnabled}},0) : {}
  84. if (video_info && video_info.of1){
  85. objectFit = video_info.objectFit
  86. }
  87. var zoomEnabled2 = true
  88. const rtcView
  89. = (
  90. <RTCView
  91. mirror = { this.props.mirror }
  92. objectFit = { objectFit }
  93. streamURL = { stream.toURL() }
  94. style = { {...style,...avt_style} }
  95. zOrder = { this.props.zOrder } />
  96. );
  97. // tglob_au.run_dev_cbs("base_video",{RTCView,stream,that:this})
  98. // VideoTransform implements "pinch to zoom". As part of "pinch to
  99. // zoom", it implements onPress, of course.
  100. if (zoomEnabled) {
  101. return (
  102. <VideoTransform
  103. enabled = { zoomEnabled }
  104. onPress = { onPress }
  105. streamId = { stream.id }
  106. style = { {...style,...avt_style} }>
  107. { rtcView }
  108. </VideoTransform>
  109. );
  110. }
  111. // XXX Unfortunately, VideoTransform implements a custom press
  112. // detection which has been observed to be very picky about the
  113. // precision of the press unlike the builtin/default/standard press
  114. // detection which is forgiving to imperceptible movements while
  115. // pressing. It's not acceptable to be so picky, especially when
  116. // "pinch to zoom" is not enabled.
  117. return (
  118. <Pressable onPress = { onPress }>
  119. { rtcView }
  120. </Pressable>
  121. );
  122. }
  123. // RTCView has peculiarities which may or may not be platform specific.
  124. // For example, it doesn't accept an empty streamURL. If the execution
  125. // reached here, it means that we explicitly chose to not initialize an
  126. // RTCView as a way of dealing with its idiosyncrasies.
  127. return null;
  128. }
  129. }