VideoAcceptor.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div class="video-acceptor">
  3. <div>
  4. <head-image :size="120" :url="this.friend.headImage" :id="this.friend.id"></head-image>
  5. </div>
  6. <div>
  7. {{friend.nickName}} 请求和您进行视频通话...
  8. </div>
  9. <div class="video-acceptor-btn-group">
  10. <div class="icon iconfont icon-phone-accept accept" @click="accpet()"></div>
  11. <div class="icon iconfont icon-phone-reject reject" @click="reject()"></div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import HeadImage from '../common/HeadImage.vue';
  17. export default {
  18. name: "videoAcceptor",
  19. components:{HeadImage},
  20. props: {
  21. friend:{
  22. type: Object
  23. }
  24. },
  25. data(){
  26. return {
  27. offer:{}
  28. }
  29. },
  30. methods:{
  31. accpet(){
  32. let info ={
  33. friend: this.friend,
  34. master: false,
  35. offer: this.offer
  36. }
  37. this.$store.commit("showChatPrivateVideoBox",info);
  38. this.close();
  39. },
  40. reject(){
  41. this.$http({
  42. url: `/webrtc/private/reject?uid=${this.friend.id}`,
  43. method: 'post'
  44. })
  45. this.close();
  46. },
  47. failed(reason){
  48. this.$http({
  49. url: `/webrtc/private/failed?uid=${this.friend.id}&reason=${reason}`,
  50. method: 'post'
  51. })
  52. this.close();
  53. },
  54. onCall(msgInfo){
  55. console.log("onCall")
  56. this.offer = JSON.parse(msgInfo.content);
  57. if(this.$store.state.userStore.state == this.$enums.USER_STATE.BUSY){
  58. this.failed("对方正忙,暂时无法接听");
  59. return;
  60. }
  61. // 超时未接听
  62. this.timer && clearTimeout(this.timer);
  63. this.timer = setTimeout(()=>{
  64. this.failed("对方未接听");
  65. },30000)
  66. },
  67. onCancel(){
  68. this.$message.success("对方取消了呼叫");
  69. this.close();
  70. },
  71. handleMessage(msgInfo){
  72. if(msgInfo.type == this.$enums.MESSAGE_TYPE.RTC_CALL){
  73. this.onCall(msgInfo);
  74. }else if(msgInfo.type == this.$enums.MESSAGE_TYPE.RTC_CANCEL){
  75. this.onCancel();
  76. }
  77. },
  78. close(){
  79. this.timer && clearTimeout(this.timer);
  80. this.$emit("close");
  81. }
  82. }
  83. }
  84. </script>
  85. <style scoped lang="scss">
  86. .video-acceptor {
  87. position: absolute;
  88. right: 1px;
  89. bottom: 1px;
  90. width: 250px;
  91. height: 250px;
  92. padding: 10px;
  93. text-align: center;
  94. background-color: #eeeeee;
  95. border: #dddddd solid 1px;
  96. .video-acceptor-btn-group {
  97. display: flex;
  98. justify-content: space-around;
  99. margin-top: 20px;
  100. .icon {
  101. font-size: 50px;
  102. cursor: pointer;
  103. &.accept {
  104. color: green;
  105. }
  106. &.reject {
  107. color: red;
  108. }
  109. }
  110. }
  111. }
  112. </style>