美文网首页
vue-cli3.0 Typescript 项目集成环信WebI

vue-cli3.0 Typescript 项目集成环信WebI

作者: _sands | 来源:发表于2019-04-08 13:00 被阅读0次

项目背景

环信webim 官方没有vue版本的,自己就根据sdk重写了个vue版本的,只实现了基础的 登录 群组功能,其他的可以根据需要参考官方文档,添加相应的功能。

环信webim SDK相关文档:
http://docs-im.easemob.com/im/web/intro/start

先使用vue-cli新建一个typescript项目


项目文件结构

集成webim

安装环信sdk和strophe.js 这两个是必须的

cnpm install easemob-websdk --save
cnpm install strophe.js --save
cnpm install crypto-js --save
cnpm install underscore --save

  • 打开node_modules/easemob-websdk/src/connection.js

添加组件
在components中添加 WebIM.ts

// 引入Strophe方法
var Strophejs = require('strophe.js');
var Strophe = (Strophejs as any).Strophe;

// 给Strophe.Connection 添加方法
Strophe.Connection.prototype.setJid = (jid: any) => {
    Strophe.Connection.jid = jid;
    Strophe.Connection.authzid = Strophe.getBareJidFromJid(Strophe.Connection.jid);
    Strophe.Connection.authcid = Strophe.getNodeFromJid(Strophe.Connection.jid);
}

Strophe.Connection.prototype.getJid = () => {
    return Strophe.Connection.jid;
}

(window as any).Strophe = Strophe;

var WebIM = require('easemob-websdk') as any;

//配置文件参考环信demo
var config = {
    xmppURL: 'im-api.easemob.com',
    apiURL: (location.protocol === 'https:' ? 'https:' : 'http:') + '//a1.easemob.com',
    appkey: 'easemob-demo#chatdemoui',
    https: false,
    isMultiLoginSessions: true,
    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: true,
    saveLocal: false,
    encrypt: {
        type: 'none'
    }
}

//初始化配置
WebIM.config = config

var conn: any = () => {
    return 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
    });
}

export interface CurrentUserInfo {
    access_token: string,
    expires_in: number,
    user: {
        activated: string,
        nickname: string,
        type: string,
        username: string,
        uuid: string
    }
}

export default {
    conn,
    WebIM
};

运行效果

image.png

git仓库地址:
https://github.com/sandsli/huanxin-vue

相关文章

  • vue-cli3.0 Typescript 项目集成环信WebI

    项目背景 环信webim 官方没有vue版本的,自己就根据sdk重写了个vue版本的,只实现了基础的 登录 群组功...

  • 环信UI3.0的集成方法

    介绍一下把环信EaseUI集成到项目中的具体实现步骤。 1.集成UI之前要把环信的SDK集成到项目中,环信SDK有...

  • iOS开发-集成环信即时通讯会话列表和聊天头像的设置

    环信SDK集成 请参考iOS开发-在现有项目中集成环信SDK及EaseUI或者参考官方文档 此操作只针对已集成环信...

  • iOS开发-在现有项目中集成环信SDK及EaseUI

    公司项目中需要集成即时聊天的功能,在现有项目的基础上集成环信最新的SDK遇到了很多坑 注册和创建应用 环信开发文档...

  • 基于环信客服SDK集成华为、小米推送

    集成华为推送 下载环信最新的SDK 将项目中的hmspush模块导入自己的项目 环信目录.PNG注意:不要修改模块...

  • 002. 集成Typescript

    3. 项目中集成typescript 参考文档 主要步骤如下: 在项目中添加 Typescript 在项目中添加 ...

  • IPV6适配之环信SDK

    项目中集成了环信,在IPV6 下无法登录环信的聊天服务器,无法聊天,因此需要适配环信 ,去年7月集成的版本应该是...

  • 集成环信EaseUI

    记录下项目中集成环信的坑。当做个总结。1.昵称显示,2.自定义表情,3.忘了(好像没了) 一、集成环信 ...

  • 环信

    iOS 集成环信(四) 群聊iOS 环信集成(五) 加载会话列表

  • 环信聊天室demo

    开发一个直播项目需要用到环信聊天室,折腾后自己集成环信聊天不带语音版本,集成环信UI删减一些不要的东西1.需要在x...

网友评论

      本文标题:vue-cli3.0 Typescript 项目集成环信WebI

      本文链接:https://www.haomeiwen.com/subject/ylawvqtx.html