-
Notifications
You must be signed in to change notification settings - Fork 67
/
index.js
57 lines (56 loc) · 2.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//MiniCore
import MiniCore from 'easemob-websdk/miniCore/miniCore'
import * as contactPlugin from 'easemob-websdk/contact/contact'
import * as groupPlugin from 'easemob-websdk/group/group'
import * as presencePlugin from 'easemob-websdk/presence/presence'
import * as localCachePlugin from 'easemob-websdk/localCache/localCache'
import {
DEFAULT_EASEMOB_APPKEY,
DEFAULT_EASEMOB_SOCKET_URL,
DEFAULT_EASEMOB_REST_URL
} from '../config'
let miniCore = {}
const IM_IS_OPEN_CUSTOM_SERVER_CONFIG =
JSON.parse(
window.localStorage.getItem('IM_IS_OPEN_CUSTOM_SERVER_CONFIG')
) || false
const webimConfig = window.localStorage.getItem('webimConfig')
const CUSTOM_CONFIG = (webimConfig && JSON.parse(webimConfig)) || {}
const initEMClient = () => {
// 读取自定义配置(因demo需要自定义配置,非必须)
const configOptions = {}
console.log(
'IM_IS_OPEN_CUSTOM_SERVER_CONFIG',
IM_IS_OPEN_CUSTOM_SERVER_CONFIG
)
if (IM_IS_OPEN_CUSTOM_SERVER_CONFIG) {
Object.assign(configOptions, {
appKey: CUSTOM_CONFIG.appKey
? CUSTOM_CONFIG.appKey
: DEFAULT_EASEMOB_APPKEY,
isHttpDNS: !CUSTOM_CONFIG.isPrivate, //取反isPrivate
url: CUSTOM_CONFIG.imWebsocketServer
? CUSTOM_CONFIG.imWebsocketServer
: DEFAULT_EASEMOB_SOCKET_URL,
apiUrl: CUSTOM_CONFIG.restServer
? `${CUSTOM_CONFIG.restServer}:${CUSTOM_CONFIG.port}`
: DEFAULT_EASEMOB_REST_URL
})
} else {
Object.assign(configOptions, {
appKey: DEFAULT_EASEMOB_APPKEY
})
console.log('configOptions', configOptions)
}
miniCore = new MiniCore({ ...configOptions })
return miniCore
}
initEMClient()
if (Object.keys(miniCore).length) {
//注册插件
miniCore.usePlugin(contactPlugin)
miniCore.usePlugin(groupPlugin)
miniCore.usePlugin(presencePlugin)
miniCore.usePlugin(localCachePlugin, 'localCache')
}
export default miniCore