vidioCall.vue 5.0 KB

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