webRTCVideoView.nvue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view >
  3. <view class="SvideoView">
  4. <wrs-uts-webrtc-view ref='localView' :style="'width:'+width+'px;height:'+height+'px;background-color:black;'"
  5. @onLoadView="onLoadLocalView"></wrs-uts-webrtc-view>
  6. </view>
  7. <wrs-uts-webrtc-view v-for="item in otherPersons"
  8. :style="'width:'+width+'px;height:'+height+'px;margin-top:20px;background-color: black;'"
  9. :userId="item.userId" @onLoadView="onLoadRemoteView(index)"></wrs-uts-webrtc-view>
  10. <view class="bottomfloatV">
  11. <view class="cInRowS" style="width: 700rpx;margin-left: 25rpx;">
  12. <image style="width: 100rpx;height: 100rpx;" src="/static/mine/qiehunsxt.png" mode="scaleToFill" @click="switchCamera"></image>
  13. <text class="text-black text-lg">{{stateNote}}</text>
  14. <image style="width: 100rpx;height: 100rpx;margin-left: 40rpx;" src="/static/mine/icon_off.png" mode="scaleToFill" @click="guangduan"></image>
  15. <!-- <image style="width: 100rpx;height: 100rpx;margin-left: 40rpx;" src="/static/mine/ysq_off.png" mode="scaleToFill" @click="jingyin"></image> -->
  16. </view>
  17. </view>
  18. <!-- <button @click="switchCamera">切换摄像头</button>
  19. <button @click="pause">暂停</button>
  20. <button @click="resume">继续</button> -->
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. const {
  27. windowWidth,
  28. windowHeight
  29. } = uni.getSystemInfoSync();
  30. let height = windowWidth / (16.0 / 9.0);
  31. return {
  32. width: windowWidth/2.5,
  33. height: height,
  34. windowWidth: windowWidth,
  35. windowHeight: windowHeight,
  36. isFront: true,
  37. friendId:'',
  38. otherPersons:[],
  39. stateNote:'已连接'
  40. }
  41. },
  42. onLoad(option) {
  43. uni.$on('webRTCvideoE', (data) => {
  44. console.log('Received webRTCvideoE:', data.msg);
  45. let js=JSON.parse(data.msg);
  46. console.log(js)
  47. if(js.type=='isClose'){
  48. uni.navigateBack();
  49. }
  50. if(js.type=='users'){
  51. this.otherPersons = js.users;
  52. console.log('this.users',this.users)
  53. }
  54. if(js.type=='state'){
  55. this.stateNote = js.stateNote;
  56. }
  57. });
  58. },
  59. onUnload() {
  60. uni.$off('webRTCvideoE');
  61. },
  62. methods: {
  63. pause(){
  64. this.$refs.localView.stopCapture()
  65. },
  66. resume(){
  67. this.$refs.localView.resumeCapture()
  68. },
  69. onLoadLocalView(p) {
  70. console.log("onLoadLocalView")
  71. // 渲染本地视频界面
  72. this.$refs.localView.renderLocalVideo()
  73. },
  74. onLoadRemoteView(p) {
  75. console.log("显示远程视频流:",this.friendId)
  76. //this.$refs.remoteView.renderRemoteVideo(''+this.friendId)
  77. },
  78. switchCamera(){
  79. this.isFront = !this.isFront
  80. this.$refs.localView.switchCamera(this.isFront)
  81. },
  82. guangduan(){
  83. uni.navigateBack();
  84. }
  85. }
  86. }
  87. </script>
  88. <style>
  89. .container {
  90. display: flex;
  91. flex-direction: row;
  92. }
  93. .SvideoView{
  94. position: fixed;
  95. flex-direction: row;
  96. align-items: center;
  97. right: 0;
  98. top: 0;
  99. z-index: 999;
  100. }
  101. .bottomfloatV{
  102. position: fixed;
  103. flex-direction: row;
  104. align-items: center;
  105. left: 0;
  106. right: 0;
  107. bottom: 0;
  108. z-index: 999;
  109. height: 180rpx;
  110. }
  111. .cInRowS{
  112. display: flex;
  113. flex-direction: row;
  114. align-items: center;
  115. justify-content:space-between;
  116. }
  117. </style>