vidioCall.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. ddmark1:0,
  22. ddmark2:0,
  23. ddmark3:0,
  24. jsthmark:0
  25. }
  26. },
  27. onLoad(option) {
  28. var language = uni.getStorageSync('language');
  29. this.webUrl='/hybrid/html/voices/audio.html?language='+language;
  30. //this.webUrl='/hybrid/html/voices/index.html?';
  31. plus.camera.getCamera();
  32. const a = plus.audio.getRecorder();
  33. a.record();
  34. a.stop();
  35. if(option.caller==1){
  36. this.isCaller=true;
  37. this.imUser = uni.getStorageSync('imUser');
  38. this.userId=this.imUser.userId;
  39. //this.ringoffImCall();
  40. }
  41. uni.onPushMessage((res) => {
  42. console.log('onPushMessage',res);
  43. var content=res.data.content;
  44. plus.runtime.setBadgeNumber(0);
  45. if(content.indexOf("发起通话")!=-1){
  46. if(that.ddmark1!=0){
  47. this.getCallmsg();
  48. }
  49. return;
  50. }
  51. if(content.indexOf("通话已被")!=-1){
  52. if(that.jsthmark==0){
  53. that.jsthmark=1;
  54. if(wv){
  55. wv.evalJS('duifangguaduan()');
  56. }
  57. }
  58. }
  59. });
  60. var that = this;
  61. console.log('plus.globalEvent.addEventListener')
  62. plus.globalEvent.addEventListener('plusMessage', function(msg){
  63. console.log('----',msg.data.args.data.arg)//web传来的参数
  64. if(msg.data.args.data.arg){
  65. var type = msg.data.args.data.arg.type;
  66. if(type==99){//webviewready
  67. if(that.ddmark1==0){
  68. that.ddmark1=1;
  69. setTimeout(function() {
  70. that.webviewonReady();
  71. }, 600); //需要延时一下,防抖动
  72. }
  73. return;
  74. }
  75. if(type==88){
  76. uni.navigateBack();
  77. return;
  78. }
  79. if(type==2){
  80. console.log('222',that.ddmark2)
  81. if(that.ddmark2==0){
  82. that.ddmark2=1;
  83. that.upDatapushmsg(that.userId,msg.data.args.data.arg)
  84. }
  85. }
  86. if(type==3){
  87. console.log('333',that.ddmark3)
  88. if(that.ddmark3==0){
  89. that.ddmark3=1;
  90. setTimeout(function() {
  91. //that.pushMsg(that.imUser.cid,msg.data.args.data.arg.data);
  92. that.upDatapushmsg(that.userId,msg.data.args.data.arg)
  93. }, 600); //需要延时一下,防抖动
  94. }
  95. }
  96. }
  97. });
  98. },
  99. onShow() {
  100. getApp().globalData.imViewOpen=true;
  101. },
  102. onUnload() {
  103. //plus.globalEvent.removeEventListener('plusMessage');
  104. this.ringoffImCall();
  105. getApp().globalData.imViewOpen=false;
  106. console.log('onUnload');
  107. },
  108. methods: {
  109. webviewonReady(){
  110. var currentWebview = this.$scope.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
  111. if(currentWebview==null){
  112. return;
  113. }
  114. wv = currentWebview.children()[0];
  115. if(this.isCaller){
  116. var that = this;
  117. var obj={
  118. payload:'',
  119. type:1
  120. };
  121. var str = JSON.stringify(obj);
  122. console.log(obj);
  123. wv.evalJS('appAct('+str+')');
  124. }
  125. else{
  126. this.getCallmsg();
  127. }
  128. },
  129. plusMessage(msg){
  130. },
  131. upDatapushmsg(userID,payload){
  132. console.log(userID,payload)
  133. var content={
  134. userID:userID,
  135. content:payload
  136. }
  137. api('userCall',{
  138. callId:userID,
  139. content:JSON.stringify(content)
  140. },res=>{
  141. console.log(res)
  142. },failc=>{
  143. //console.log('getadvertis----',failc)
  144. })
  145. },
  146. getCallmsg(){
  147. api('getCall',{
  148. },res=>{
  149. console.log(res)
  150. if(res.data.code==200){
  151. if(this.isCaller){
  152. var answer = res.data.data.answer;
  153. this.userId=answer.userID;
  154. var obj={
  155. payload:answer.content.data,
  156. type:answer.content.type
  157. };
  158. var str = JSON.stringify(obj);
  159. wv.evalJS('appAct('+str+')');
  160. return
  161. }
  162. var content = res.data.data.content;
  163. this.userId=content.userID;
  164. var obj={
  165. payload:content.content.data,
  166. type:content.content.type
  167. };
  168. var str = JSON.stringify(obj);
  169. wv.evalJS('appAct('+str+')');
  170. }
  171. },failc=>{
  172. //console.log('getadvertis----',failc)
  173. })
  174. },
  175. ringoffImCall(){
  176. api('ringoff',{
  177. },res=>{
  178. console.log(res)
  179. },failc=>{
  180. //console.log('getadvertis----',failc)
  181. })
  182. }
  183. }
  184. }
  185. </script>
  186. <style>
  187. </style>