ring.nvue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view class="call-view">
  3. <!-- 本地视频画面 -->
  4. <!-- #ifdef APP -->
  5. <grtc-video v-if="currentCall.mediaType === 1" :userId="currentUser.id" class="main-video"></grtc-video>
  6. <!-- #endif -->
  7. <!-- #ifdef H5 -->
  8. <web-grtc-video v-if="currentCall.mediaType === 1" :userId="currentUser.id" class="main-video"></web-grtc-video>
  9. <!-- #endif -->
  10. <cover-view class="profile">
  11. <image class="user-avatar" mode="widthFix" :src="currentCall.caller.data.avatar"></image>
  12. <text class="user-name">{{currentCall.caller.data.name}}</text>
  13. </cover-view>
  14. <view class="status-box">
  15. <text class="status-notice">邀请你进行通话</text>
  16. <image src="/static/images/load.gif" class="loading"></image>
  17. </view>
  18. <view class="action-box">
  19. <view class="action-item" @click="end()">
  20. <view class="end-background">
  21. <image class="action-icon" src="/static/images/phoneEnd.png"></image>
  22. </view>
  23. <text class="action-text">拒绝</text>
  24. </view>
  25. <view class="action-item" @click="accept()">
  26. <view class="accept-background">
  27. <image class="action-icon rotate" src="/static/images/phoneEnd.png"></image>
  28. </view>
  29. <text class="action-text">接听</text>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import webGrtcVideo from '../components/web-grtc-video/web-grtc-video.vue';
  36. const GRTC = uni.$GRTC;
  37. export default {
  38. data() {
  39. return {
  40. currentCall: GRTC.currentCall(),
  41. currentUser: uni.$currentUser
  42. }
  43. },
  44. components: {
  45. webGrtcVideo,
  46. },
  47. onLoad() {
  48. this.initListener();
  49. },
  50. onUnload() {
  51. GRTC.off(GRTC.EVENT.USER_QUIT, this.onUserQuit);
  52. },
  53. onBackPress(event) {
  54. return event.from === 'backbutton'; // 禁止安卓侧滑返回
  55. },
  56. methods: {
  57. initListener() {
  58. GRTC.on(GRTC.EVENT.USER_QUIT, this.onUserQuit);
  59. },
  60. onUserQuit(event) {
  61. const username = event.user.id === this.currentUser.id ? '' : event.user.data.name;
  62. let message = '';
  63. switch (event.reason) {
  64. case 'RING_TIMEOUT':
  65. message = `超时未接听`;
  66. break;
  67. case 'GOEASY_DISCONNECTED':
  68. message = `${username}网络异常`;
  69. break;
  70. case 'HANDLED_ON_ANOTHER_DEVICE':
  71. message = `其他设备已处理`;
  72. break;
  73. case 'CANCELLED':
  74. message = `${username}已取消`;
  75. break;
  76. case 'REJECTED':
  77. message = `已拒绝`;
  78. break;
  79. }
  80. uni.showToast({
  81. title: message,
  82. icon: "none"
  83. });
  84. uni.navigateBack();
  85. },
  86. accept() {
  87. GRTC.accept().then(() => {
  88. uni.redirectTo({
  89. url: './call'
  90. });
  91. }).catch((e) => {
  92. console.log('e', e);
  93. })
  94. },
  95. end() {
  96. GRTC.end();
  97. },
  98. }
  99. }
  100. </script>
  101. <style scoped>
  102. @import url('/static/style/rtcCallStyle.css');
  103. </style>