vidioCall.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view>
  3. <view class="">
  4. <web-view style="background-color:deeppink;height: 500rpx;" ref="webview" :src="webUrl"></web-view>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. import api from "@/pages/api/api.js"
  10. var wv=null;//计划创建的webview
  11. export default {
  12. data() {
  13. return {
  14. //webUrl: '/hybrid/html/voices/index.html?',
  15. webUrl: '',
  16. isCaller:false,
  17. offer:'',
  18. cid:'',
  19. imUser:'',
  20. userId:'',
  21. ddmark:0
  22. }
  23. },
  24. onLoad(option) {
  25. var language = uni.getStorageSync('language');
  26. this.webUrl='/hybrid/html/voices/audio.html?language='+language;
  27. plus.camera.getCamera();
  28. const a = plus.audio.getRecorder();
  29. a.record();
  30. a.stop();
  31. if(option.caller==1){
  32. this.isCaller=true;
  33. this.imUser = uni.getStorageSync('imUser');
  34. this.userId=this.imUser.userId;
  35. //this.ringoffImCall();
  36. }
  37. uni.onPushMessage((res) => {
  38. console.log('onPushMessage',res);
  39. var content=res.data.content;
  40. plus.runtime.setBadgeNumber(0);
  41. if(content.indexOf("通话")!=-1){
  42. this.getCallmsg();
  43. }
  44. });
  45. var that = this;
  46. console.log('plus.globalEvent.addEventListener')
  47. plus.globalEvent.addEventListener('plusMessage', function(msg) {
  48. console.log('----',msg.data.args.data.arg)//web传来的参数
  49. if(msg.data.args.data.arg){
  50. var type = msg.data.args.data.arg.type;
  51. if(type==99){//webviewready
  52. if(that.ddmark==0){
  53. that.ddmark=1;
  54. setTimeout(function() {
  55. that.webviewonReady();
  56. that.ddmark=0;
  57. }, 600); //需要延时一下,防抖动
  58. }
  59. return;
  60. }
  61. if(type==88){
  62. uni.navigateBack();
  63. return;
  64. }
  65. if(type==2||type==3){
  66. if(that.ddmark==0){
  67. that.ddmark=1;
  68. setTimeout(function() {
  69. //that.pushMsg(that.imUser.cid,msg.data.args.data.arg.data);
  70. that.upDatapushmsg(that.userId,msg.data.args.data.arg)
  71. that.ddmark=0;
  72. }, 600); //需要延时一下,防抖动
  73. }
  74. }
  75. }
  76. })
  77. },
  78. onShow() {
  79. getApp().globalData.imViewOpen=true;
  80. },
  81. onUnload() {
  82. getApp().globalData.imViewOpen=false;
  83. },
  84. methods: {
  85. webviewonReady(){
  86. var currentWebview = this.$scope.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
  87. wv = currentWebview.children()[0];
  88. if(this.isCaller){
  89. var that = this;
  90. var obj={
  91. payload:'',
  92. type:1
  93. };
  94. var str = JSON.stringify(obj);
  95. console.log(obj);
  96. wv.evalJS('appAct('+str+')');
  97. }
  98. else{
  99. this.getCallmsg();
  100. }
  101. },
  102. upDatapushmsg(userID,payload){
  103. console.log(userID,payload)
  104. var content={
  105. userID:userID,
  106. content:payload
  107. }
  108. api('userCall',{
  109. callId:userID,
  110. content:JSON.stringify(content)
  111. },res=>{
  112. console.log(res)
  113. },failc=>{
  114. //console.log('getadvertis----',failc)
  115. })
  116. },
  117. getCallmsg(){
  118. api('getCall',{
  119. },res=>{
  120. console.log(res)
  121. if(res.data.code==200){
  122. if(this.isCaller){
  123. var answer = res.data.data.answer;
  124. this.userId=answer.userID;
  125. var obj={
  126. payload:answer.content.data,
  127. type:answer.content.type
  128. };
  129. var str = JSON.stringify(obj);
  130. wv.evalJS('appAct('+str+')');
  131. return
  132. }
  133. var content = res.data.data.content;
  134. this.userId=content.userID;
  135. var obj={
  136. payload:content.content.data,
  137. type:content.content.type
  138. };
  139. var str = JSON.stringify(obj);
  140. wv.evalJS('appAct('+str+')');
  141. }
  142. },failc=>{
  143. //console.log('getadvertis----',failc)
  144. })
  145. },
  146. ringoffImCall(){
  147. api('ringoff',{
  148. },res=>{
  149. console.log(res)
  150. },failc=>{
  151. //console.log('getadvertis----',failc)
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style>
  158. </style>