ring.nvue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view class="call-view">
  3. <cover-view class="profile">
  4. <image class="caller-avatar" mode="widthFix" :src="currentCall.caller.data.avatar"></image>
  5. <text class="caller-name">{{currentCall.caller.data.name}}</text>
  6. </cover-view>
  7. <view class="status-box">
  8. <text class="status-notice">邀请你加入多人通话</text>
  9. <image src="/static/images/load.gif" class="loading"></image>
  10. </view>
  11. <view class="callee-info">
  12. <text class="callee-text">参与通话的还有:</text>
  13. <view class="callee-list">
  14. <view v-for="(callee, index) in currentCall.callees" :key="index" >
  15. <image class="callee-avatar" :src="callee.data.avatar" mode="widthFix"></image>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="action-box">
  20. <view class="action-item" @click="end()">
  21. <view class="end-background">
  22. <image class="action-icon" src="/static/images/phoneEnd.png"></image>
  23. </view>
  24. <text class="action-text">拒绝</text>
  25. </view>
  26. <view class="action-item" @click="accept()">
  27. <view class="accept-background">
  28. <image class="action-icon rotate" src="/static/images/phoneEnd.png"></image>
  29. </view>
  30. <text class="action-text">接听</text>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. const GRTC = uni.$GRTC;
  37. export default {
  38. data() {
  39. return {
  40. currentCall: GRTC.currentCall(),
  41. }
  42. },
  43. onLoad() {
  44. this.initListener();
  45. },
  46. onUnload() {
  47. GRTC.off(GRTC.EVENT.USER_QUIT, this.onUserQuit);
  48. GRTC.off(GRTC.EVENT.CALL_ENDED, this.onCallEnded);
  49. },
  50. onBackPress(event) {
  51. return event.from === 'backbutton'; // 禁止安卓侧滑返回
  52. },
  53. methods: {
  54. initListener() {
  55. GRTC.on(GRTC.EVENT.USER_QUIT, this.onUserQuit);
  56. GRTC.on(GRTC.EVENT.CALL_ENDED, this.onCallEnded);
  57. },
  58. onUserQuit(event) {
  59. const username = event.user.id === uni.$currentUser.id ? '' : event.user.data.name;
  60. let message = '';
  61. switch (event.reason) {
  62. case 'RING_TIMEOUT':
  63. message = `超时未接听`;
  64. break;
  65. case 'GOEASY_DISCONNECTED':
  66. message = `${username}网络异常`;
  67. break;
  68. case 'HANDLED_ON_ANOTHER_DEVICE':
  69. message = `其他设备已处理`;
  70. break;
  71. case 'CANCELLED':
  72. message = `${username}已取消`;
  73. break;
  74. case 'REJECTED':
  75. message = `${username}已拒绝`;
  76. break;
  77. }
  78. uni.showToast({
  79. title: message,
  80. icon: "none"
  81. });
  82. },
  83. onCallEnded() {
  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>