Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ webim-vue3-demo 是基于环信 sdk 开发的一款具有单聊、群聊等功

```bash
# install dependencies
npm install or yarn install
npm install

# serve with hot reload at localhost:9001
npm run dev or yarn run dev
Expand Down Expand Up @@ -74,12 +74,12 @@ npm run build --report

> SDK 的初始化是 IM 功能实现的基石必须经过`引入SDK`、`实例化SDK`、`挂载SDK事件监听`、`引入实例`这几步。

- [SDK 所需配置](./src/IM/config/index.js)
- [初始化 SDK](./src/IM/miniCore/index.js)
- [导出初始化 SDK 实例](./src/IM/index.js)
- [实现逻辑时 SDK 关联常量(单独集成非必须)](./src/IM/constant/)
- [SDK 事件监听回调](./src/IM/listener/)
- [挂载 SDK 所需事件监听](./src/App.vue)
import { EMClient } from '@/IM';
import { mountAllEMListener } from '@/IM/listener';
/* [【重要】挂载IM相关监听回调](https://home.biaoxianga.cn)。 */
mountAllEMListener();
//登录im-api-v2.easecdn.com
EMClient.open({ username: '', password: '' });

> 实际使用效果如下面示例代码:

Expand Down Expand Up @@ -205,7 +205,7 @@ EMClient.open({ username: '', password: '' });
```javascript
import AgoraRTC from 'agora-rtc-sdk-ng';

const AgoraAppId = 'YOUR AOGRA APPID';
const AgoraAppId = 'YOUR AOGRA APPID';YXA6ITyaTxGoQ82Hh31A818ygg

export { AgoraAppId, AgoraRTC };
```
Expand Down
33 changes: 13 additions & 20 deletions src/IM/initwebsdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@ import EaseChatSDK from 'easemob-websdk';
import {
DEFAULT_EASEMOB_APPKEY,
DEFAULT_EASEMOB_SOCKET_URL,
DEFAULT_EASEMOB_REST_URL,
DEFAULT_EASEMOB_REST_URL
} from './config';

// 读取自定义配置(因demo需要自定义配置,非必须)
const webimConfig = window.localStorage.getItem('webimConfig');
const CUSTOM_CONFIG = (webimConfig && JSON.parse(webimConfig)) || {};
const CUSTOM_CONFIG = (webimConfig && JSON.parse(webimConfig)) || {
appKey: '1190250126193957',
imServer: 'im-api-v2.easecdn.com',
restServer: 'im-api-v2.easemob.com'
};

console.log('>>>>>>webimConfig', CUSTOM_CONFIG);

//存放实例化后所有的方法
// let EaseIMClient = {};
// window.EaseIM = EaseIM = Easemob_SDK;
//实例化环信SDK
/*
* isHttpDNS: isPrivate为true开启私有化配置则走自有配置的url以及apiUrl,
* 否则为true就SDK自助获取DNS地址。
* 【特别注意】如果不需要私有化配置,也就是自己定义url以及apiUrl。isHttpDNS、url、apiUrl,均可不用填写只用填入appKey!SDK内部会进行自动获取!
**/
// 实例化环信SDK
const EaseChatClient = new EaseChatSDK.connection({
appKey: CUSTOM_CONFIG.appKey ? CUSTOM_CONFIG.appKey : DEFAULT_EASEMOB_APPKEY,
isHttpDNS: !CUSTOM_CONFIG.isPrivate, //取反isPrivate
url: CUSTOM_CONFIG.imServer
? CUSTOM_CONFIG.imServer
: DEFAULT_EASEMOB_SOCKET_URL,
apiUrl: CUSTOM_CONFIG.restServer
? `${CUSTOM_CONFIG.restServer}:${CUSTOM_CONFIG.port}`
: DEFAULT_EASEMOB_REST_URL,
isHttpDNS: !CUSTOM_CONFIG.isPrivate, // 取反isPrivate
url: CUSTOM_CONFIG.imServer ? CUSTOM_CONFIG.imServer : DEFAULT_EASEMOB_SOCKET_URL,
apiUrl: CUSTOM_CONFIG.restServer ? `${CUSTOM_CONFIG.restServer}:${CUSTOM_CONFIG.port}` : DEFAULT_EASEMOB_REST_URL
});
//向EaseChatClient下添加构建消息方法。
EaseChatClient.Message = EaseChatSDK.message;

export { EaseChatSDK, EaseChatClient };