vue中集成环信webIm

"strophe.js": "^1.3.1",

"easemob-websdk": "^1.8.4",


webIm.config.js

import Strophe from 'strophe.js'

/* Strophe.Connection 内缺少两个方法 */

Strophe.Strophe.Connection.prototype.setJid = function(jid) {

        this.jid = jid; this.authzid = Strophe.Strophe.getBareJidFromJid(this.jid);

        this.authcid = Strophe.Strophe.getNodeFromJid(this.jid);

}

Strophe.Strophe.Connection.prototype.getJid = function () {

        return this.jid;

}

import Vue from 'vue'import websdk from 'easemob-websdk'

let webIM = window.WebIM = websdk;

webIM.config = {

        xmppURL: 'im-api.easemob.com',

        apiURL: (location.protocol === 'https:' ? 'https:' : 'http:') + '//a1.easemob.com',

        appkey:  '*************',

        https: false,

        isMultiLoginSessions: false,

        isAutoLogin: true,

        isWindowSDK: false,

        isSandBox: false,

        isDebug: false,

        autoReconnectNumMax: 2,

        autoReconnectInterval: 2,

        isWebRTC: (/Firefox/.test(navigator.userAgent) || /WebKit/.test(navigator.userAgent)) && /^https:$/.test(window.location.protocol),         heartBeatWait: 4500,

        isHttpDNS: false,

        msgStatus: true,

        delivery: true,

        read: false,

        encrypt: { type: 'none' },

        password: '***********'

};

const imConn = new webIM.connection({

        isMultiLoginSessions: webIM.config.isMultiLoginSessions,

        https: typeof webIM.config.https === 'boolean' ? webIM.config.https : location.protocol === 'https:',

        url: webIM.config.xmppURL,

        isAutoLogin: true,

        heartBeatWait: webIM.config.heartBeatWait,

        autoReconnectNumMax: webIM.config.autoReconnectNumMax,

        autoReconnectInterval: webIM.config.autoReconnectInterval,

        apiUrl: webIM.config.apiURL

})

Vue.prototype.$WebIM = webIM;

Vue.prototype.$imConn = imConn;

然后就可以在vue文件里面引用webIm.config.js,使用this.$imConn登录了。

你可能感兴趣的:(vue中集成环信webIm)