dial.nvue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="call-view">
  3. <!-- 本地视频画面 -->
  4. <!-- #ifdef APP -->
  5. <grtc-video v-if="currentCall.mediaType === 1" :userId="currentCall.caller.id" class="main-video"></grtc-video>
  6. <!-- #endif -->
  7. <!-- #ifdef H5 -->
  8. <web-grtc-video v-if="currentCall.mediaType === 1" :userId="currentCall.caller.id" class="main-video"></web-grtc-video>
  9. <!-- #endif -->
  10. <view class="profile">
  11. <image class="user-avatar" mode="widthFix" :src="callee.data.avatar"></image>
  12. <text class="user-name">{{callee.data.name}}</text>
  13. </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>
  26. </view>
  27. </template>
  28. <script>
  29. import webGrtcVideo from '../components/web-grtc-video/web-grtc-video.vue';
  30. const GRTC = uni.$GRTC;
  31. export default {
  32. data() {
  33. return {
  34. currentCall: GRTC.currentCall(),
  35. callee: GRTC.currentCall().callees[0],
  36. }
  37. },
  38. components: {
  39. webGrtcVideo,
  40. },
  41. onLoad() {
  42. this.initListener();
  43. },
  44. onUnload() {
  45. GRTC.off(GRTC.EVENT.USER_ACCEPTED, this.onUserAccepted);
  46. GRTC.off(GRTC.EVENT.USER_RANG, this.onUserRang);
  47. GRTC.off(GRTC.EVENT.USER_QUIT, this.onUserQuit);
  48. },
  49. onBackPress(event) {
  50. return event.from === 'backbutton'; // 禁止安卓侧滑返回
  51. },
  52. methods: {
  53. initListener() {
  54. GRTC.on(GRTC.EVENT.USER_ACCEPTED, this.onUserAccepted);
  55. GRTC.on(GRTC.EVENT.USER_RANG, this.onUserRang);
  56. GRTC.on(GRTC.EVENT.USER_QUIT, this.onUserQuit);
  57. },
  58. onUserAccepted(event) {
  59. uni.showToast({
  60. title: event.user.data.name+"已接听",
  61. icon: "none"
  62. });
  63. uni.redirectTo({
  64. url: './call'
  65. });
  66. },
  67. onUserRang(event) {
  68. uni.showToast({
  69. title: event.user.data.name+"已响铃",
  70. icon: "none"
  71. });
  72. },
  73. onUserQuit(event) {
  74. const username = event.user.data.name;
  75. let message = '';
  76. switch (event.reason) {
  77. case 'DIAL_TIMEOUT':
  78. message = `拨打超时`;
  79. break;
  80. case 'CANCELLED':
  81. message = `已取消`;
  82. break;
  83. case 'REJECTED':
  84. message = `${username}已拒绝`;
  85. break;
  86. case 'GOEASY_DISCONNECTED':
  87. message = `${username}网络异常`;
  88. break;
  89. }
  90. uni.showToast({title: message,icon: "none"});
  91. uni.navigateBack();
  92. },
  93. end() {
  94. GRTC.end();
  95. },
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. @import url('/static/style/rtcCallStyle.css');
  101. </style>