dial.nvue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="call-view">
  3. <view class="nav-bar">
  4. <text class="timer">等待接听</text>
  5. </view>
  6. <view class="user-list">
  7. <view v-for="(callee,index) in currentCall.callees" :key="index" class="user-item">
  8. <image class="user-item-avatar" mode="widthFix" :src="callee.data.avatar"></image>
  9. </view>
  10. <view class="user-item">
  11. <!-- #ifdef APP -->
  12. <grtc-video v-if="currentCall.mediaType === 1" :userId="currentCall.caller.id" class="caller-view"></grtc-video>
  13. <image v-else class="user-item-avatar" mode="widthFix" :src="currentCall.caller.data.avatar"></image>
  14. <!-- #endif -->
  15. <!-- #ifdef H5 -->
  16. <web-grtc-video v-if="currentCall.mediaType === 1" :userId="currentCall.caller.id" class="caller-view"></web-grtc-video>
  17. <image v-else class="user-item-avatar" mode="widthFix" :src="currentCall.caller.data.avatar"></image>
  18. <!-- #endif -->
  19. </view>
  20. </view>
  21. <view class="action-box">
  22. <view class="action-item" @click="end()">
  23. <view class="end-background">
  24. <image class="action-icon" src="/static/images/phoneEnd.png"></image>
  25. </view>
  26. <text class="action-text">取消</text>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import webGrtcVideo from '../components/web-grtc-video/web-grtc-video.vue';
  33. const GRTC = uni.$GRTC;
  34. export default {
  35. data() {
  36. return {
  37. currentCall: GRTC.currentCall(),
  38. }
  39. },
  40. components: {
  41. webGrtcVideo,
  42. },
  43. onLoad() {
  44. this.initListener();
  45. },
  46. onUnload() {
  47. GRTC.off(GRTC.EVENT.USER_ACCEPTED, this.onUserAccepted);
  48. GRTC.off(GRTC.EVENT.USER_RANG, this.onUserRang);
  49. GRTC.off(GRTC.EVENT.USER_QUIT, this.onUserQuit);
  50. GRTC.off(GRTC.EVENT.CALL_ENDED, this.onCallEnded);
  51. },
  52. onBackPress(event) {
  53. return event.from === 'backbutton'; // 禁止安卓侧滑返回
  54. },
  55. methods: {
  56. initListener() {
  57. GRTC.on(GRTC.EVENT.USER_ACCEPTED, this.onUserAccepted);
  58. GRTC.on(GRTC.EVENT.USER_RANG, this.onUserRang);
  59. GRTC.on(GRTC.EVENT.USER_QUIT, this.onUserQuit);
  60. GRTC.on(GRTC.EVENT.CALL_ENDED, this.onCallEnded);
  61. },
  62. onUserAccepted(event) {
  63. uni.showToast({
  64. title: event.user.data.name+"已接听",
  65. icon: "none"
  66. });
  67. uni.redirectTo({
  68. url: './call'
  69. });
  70. },
  71. onUserRang(event) {
  72. uni.showToast({
  73. title: event.user.data.name+"已响铃",
  74. icon: "none"
  75. });
  76. },
  77. onUserQuit(event) {
  78. const username = event.user.data.name;
  79. let message = '';
  80. switch (event.reason) {
  81. case 'DIAL_TIMEOUT':
  82. message = `拨打超时`;
  83. break;
  84. case 'CANCELLED':
  85. message = `已取消`;
  86. break;
  87. case 'REJECTED':
  88. message = `${username}已拒绝`;
  89. break;
  90. case 'GOEASY_DISCONNECTED':
  91. message = `${username}网络异常`;
  92. break;
  93. }
  94. uni.showToast({title: message,icon: "none"});
  95. },
  96. onCallEnded() {
  97. uni.navigateBack();
  98. },
  99. end() {
  100. GRTC.end();
  101. },
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. @import url('/static/style/rtcCallStyle.css');
  107. </style>