4 Star 0 Fork 0

时辰 / sloth-web

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
assembly.js 1.63 KB
一键复制 编辑 原始数据 按行查看 历史
bijh 提交于 2016-10-10 09:50 . .
import { debug, leancloudappid, leancloudappkey } from "./app_config"
import Toast from './src/components/Toast'
import * as account from "./services/account"
import EventEmitter from "./src/common/EventEmitter.js"
// leancloud
import AV from 'leancloud-storage'
import {Realtime, TextMessage} from 'leancloud-realtime'
import {TypedMessagesPlugin, ImageMessage} from 'leancloud-realtime-plugin-typed-messages'
AV.init({ appId: leancloudappid, appKey: leancloudappkey })
export let SlothRealtime = new Realtime({
appId: leancloudappid,
plugins: [TypedMessagesPlugin],
region: 'cn'
})
SlothRealtime.on('disconnect', function () {
Toast.show("网络连接已断开", 'warn')
SlothRealtime.retry()
})
SlothRealtime.on('retry', function (attempt) {
Toast.show('正在进行第' + attempt + '次重连')
})
SlothRealtime.on('reconnect', function() {
Toast.show('网络连接已恢复')
})
export let imclient = {}
export const MessageReciveEvent = "message_recive"
export const IMClientInitEvent = "imclient_init"
let MountIMClient = (user)=> {
SlothRealtime && SlothRealtime.createIMClient(user.id).then((client) => {
imclient = client
EventEmitter.emit(IMClientInitEvent, null)
imclient.on('message', (message, conv) => {
EventEmitter.emit(MessageReciveEvent, message, conv)
})
})
}
let UnMountIMClient = ()=> {
imclient = {}
}
// Services
let MountServices = ()=> {
account.CurrentUser().then((user) => {
MountIMClient(user)
}).catch(() => {
UnMountIMClient()
})
}
MountServices()
EventEmitter.addListener(account.TokenChangedEvent, MountServices.bind(this))
1
https://gitee.com/twoours/sloth-web.git
git@gitee.com:twoours/sloth-web.git
twoours
sloth-web
sloth-web
master

搜索帮助