import Vue from 'vue';
import App from './App';
//import GoEasy from '@/uni_modules/GOEASY-IM/js_sdk/goeasy-2.13.21.esm.min.js'
import GoEasy from '@/uni_modules/GOEASY-IM/js_sdk/goeasy-2.13.24-0.esm.min.js'
import GRTC from './lib/goeasy-rtc-0.3.7.esm.min.js'
//import GRTC from './lib/goeasy-2.13.24-0.esm.min.js'
import request from '@/utils/request.js'
Vue.prototype.$http = request.http
Vue.prototype.$http2 = request.http2
Vue.prototype.$request =request
console.log("main.js")
console.log(request.baseUrl)
var header={};
header['Content-Type']='application/x-www-form-urlencoded';
uni.request({
	method: "POST",
	url: request.baseUrl + 'imSys/imAppKey',
	data: {},
	header: header,
	dataType: 'json',         
	}).then((response) => {
		 let [error, res] = response;
		 var appKey=res.data.data.appKey
		 console.log(res.data.data.appKey)
		GoEasy.init({
		    host:"hangzhou.goeasy.io",//应用所在的区域地址: 【hangzhou.goeasy.io |singapore.goeasy.io】
		    appkey:appKey,//"BC-729fefdf1ad7417daea8e62b9fce3f74",// common key
		    modules: ['im'],
		    // true表示支持通知栏提醒，false则表示不需要通知栏提醒
		    allowNotification: true //仅有效于app,小程序和H5将会被自动忽略
		});
		GRTC.init(GoEasy);
		uni.$GoEasy = GoEasy;
		uni.$GRTC = GRTC;
		
		Vue.config.productionTip = false;
		App.mpType = 'app';
		const app = new Vue({
		    ...App
		});
		app.$mount();
		
		
	})




GoEasy.onClickNotification((message) => {
    let currentUrl;
    const routes = getCurrentPages();

    if (routes && routes.length) {
        const curRoute = routes[routes.length - 1].route;
        const curParam = routes[routes.length - 1].options;
        currentUrl = '/' + curRoute + `?to=${curParam.to}`;
    }

    let newUrl;
    switch (message.toType) {
        case GoEasy.IM_SCENE.PRIVATE:
            newUrl = '/pages/privateChat?to=' + message.senderId;
            break;
        case GoEasy.IM_SCENE.GROUP:
            newUrl = '/pages/groupChat?to=' + message.groupId;
            break;
    }

    if (currentUrl !== newUrl) {
        uni.navigateTo({
            url: newUrl,
        });
    }

});

