| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <template>
- <view>
- <view class="">
- <web-view style="background-color:deeppink;height: 500rpx;" ref="webview" :src="webUrl"></web-view>
- </view>
-
- </view>
- </template>
- <script>
- import api from "@/pages/api/api.js"
- var wv=null;//计划创建的webview
- export default {
- data() {
- return {
- //webUrl: '/hybrid/html/voices/index.html?',
- webUrl: '',
- isCaller:false,
- offer:'',
- cid:'',
- imUser:'',
- userId:'',
- userName:'',
- avatar:'',
- baseUrl:'https://backend.awayqtw.com/prod-api',
- ddmark1:0,
- ddmark2:0,
- ddmark3:0,
- pushmark1:0,
- pushmark2:0,
- jsthmark:0
- }
- },
- onLoad(option) {
- this.ringoffImCall();
- plus.camera.getCamera();
- const a = plus.audio.getRecorder();
- a.record();
- a.stop();
- console.log(getApp().globalData.token);
- var language = uni.getStorageSync('language');
- //this.webUrl='/hybrid/html/voices/audio.html?language='+language;
- this.webUrl='/hybrid/html/xuanfu/index.html';
- if(option.caller==1){
- this.isCaller=true;
- this.imUser = uni.getStorageSync('imUser');
- this.userId=this.imUser.userId;
- this.userName=this.imUser.nickName;
- this.avatar=this.baseUrl+this.imUser.avatar;
- }
- uni.onPushMessage((res) => {
- console.log('onPushMessage',res);
- var content=res.data.content;
- plus.runtime.setBadgeNumber(0);
- var that = this;
- if(content.indexOf("通话请求")!=-1){
- if(that.pushmark1==0){
- that.pushmark1=1;
- that.getCallmsg();
- }
- else{
- if(that.pushmark2==0){
- that.pushmark2=1;
- that.getCallmsg();
- }
- }
- return;
- }
- if(content.indexOf("通话已被")!=-1){
- if(that.jsthmark==0){
- that.jsthmark=1;
- if(wv){
- wv.evalJS('duifangguaduan()');
- }
- }
- }
- });
- var that = this;
- console.log('plus.globalEvent.addEventListener')
- //plus.globalEvent.removeEventListener('plusMessage', null);
- plus.globalEvent.addEventListener('plusMessage', function(msg) {
- console.log('----',msg.data.args.data.arg)//web传来的参数
- if(msg.data.args.data.arg){
- var type = msg.data.args.data.arg.type;
- if(type==99){//webviewready
- if(that.ddmark1==0){
- that.ddmark1=1;
- setTimeout(function() {
- that.webviewonReady();
- }, 600); //需要延时一下,防抖动
- }
- return;
- }
- if(type==88){
- uni.navigateBack();
- return;
- }
- if(type==2){
- console.log(type);
- if(that.ddmark2==0){
- that.ddmark2=1;
- setTimeout(function() {
- //that.pushMsg(that.imUser.cid,msg.data.args.data.arg.data);
- that.upDatapushmsg(that.userId,msg.data.args.data.arg)
- }, 600); //需要延时一下,防抖动
- }
- }
- if(type==3){
- console.log(type);
- if(that.ddmark3==0){
- that.ddmark3=1;
- setTimeout(function() {
- //that.pushMsg(that.imUser.cid,msg.data.args.data.arg.data);
- that.upDatapushmsg(that.userId,msg.data.args.data.arg)
- }, 600); //需要延时一下,防抖动
- }
- }
- }
-
- })
- },
- onShow() {
- getApp().globalData.imViewOpen=true;
- },
- onUnload() {
- this.ringoffImCall();
- getApp().globalData.imViewOpen=false;
- },
- methods: {
- webviewonReady(){
- var currentWebview = this.$scope.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
- if(currentWebview==null){
- return;
- }
- wv = currentWebview.children()[0];
- if(this.isCaller){
- var obj={
- payload:{
- userName:this.userName,
- avatar:this.avatar
- },
- type:1
- };
- var str = JSON.stringify(obj);
- console.log(obj);
- wv.evalJS('appAct('+str+')');
- }
- else{
- this.getCallmsg();
- }
- },
- upDatapushmsg(userID,payload){
- console.log(userID,payload)
- var content={
- userID:userID,
- content:payload
- }
- api('userCall',{
- callId:userID,
- content:JSON.stringify(content)
- },res=>{
- console.log(res)
- },failc=>{
- //console.log('getadvertis----',failc)
- })
- },
- getCallmsg(){
- api('getCall',{
- },res=>{
- console.log(res)
- if(res.data.code==200){
- if(this.isCaller){
- var answer = res.data.data.answer;
- this.userId=answer.userID;
- var obj={
- payload:answer.content.data,
- type:answer.content.type
- };
- var str = JSON.stringify(obj);
- wv.evalJS('appAct('+str+')');
- return
- }
- var content = res.data.data.content;
- this.userId=content.userID;
- var obj={
- payload:content.content.data,
- type:content.content.type
- };
- var str = JSON.stringify(obj);
- wv.evalJS('appAct('+str+')');
- }
-
- },failc=>{
- //console.log('getadvertis----',failc)
- })
- },
- ringoffImCall(){
- api('ringoff',{
- },res=>{
- console.log(res)
-
- },failc=>{
- //console.log('getadvertis----',failc)
- })
- }
- }
- }
- </script>
- <style>
- </style>
|