flooim
flooim
flooim.flooim(config) ⇒ object
初始化SDK
Kind: static method of flooim
Returns: object
- flooim对象
Param | Type | Description |
---|---|---|
config | object |
SDK初始化设置 |
config.appid | string |
APPID |
config.ws | boolean |
连接地址前缀是否为ws/wss: true - 连接地址前缀为ws或wss, false - 连接地址前缀为http/https |
config.autoLogin | boolean |
是否自动登录 |
config.dnsServer | string | undefined |
DNS服务器地址, 可以不设置,默认为 https://dns.lanyingim.com/v2/app_dns |
config.logLevel | string |
SDK的日志等级, 默认为debug, 取值为 debug、info、warn、error 或 off, 其中off为不打印日志。 |
Example
const config = {
// dnsServer: "https://dns.lanyingim.com/v2/app_dns",
appid: "YOUR_APP_ID",
ws: false, // uniapp版需要设置为true, web版需要设置为false
autoLogin: true
};
import flooim from 'floo-3.0.0';
const im = flooim(config);
const logLevel = process.env.NODE_ENV === 'production' ? 'off' : 'debug'; // debug|info|warn|error|off
const config = {
// dnsServer: "https://dns.lanyingim.com/v2/app_dns",
appid: this.appid,
ws: false, // uniapp版需要设置为true, web版需要设置为false
autoLogin: this.intent.code || this.intent.link ? false : true,
logLevel: logLevel
};
console.log('Init floo IM for ', this.appid);
// 1. 使用 flooim script 方式
// try {
// // const im = new window.flooIM(config);
// this.$store.dispatch("actionSaveIm", im);
// this.sdkok = true;
// } catch (ex) {
// // sdk not ready, should retry later
// console.log(ex);
// setTimeout(() => {
// this.initFlooIM();
// }, 500);
// }
// 2. 使用 flooim module 模式
const im = flooim(config);
this.$store.dispatch('actionSaveIm', im);
this.addIMListeners();
flooim.login(opt)
登录
Kind: static method of flooim
Param | Type | Description |
---|---|---|
opt | object |
|
opt.name | string |
用户名 |
opt.password | string |
密码 |
Example
im.login({
//TODO: change name to username
name: loginInfo.username,
password: loginInfo.password
});
username = res.username;
that.saveLoginInfo({ username, password }, that.appid);
im.login({
name: username,
password: password
});
console.log('登录了....');
_this.im.login({ password, name: username });
this.$store.state.im.login({
name: this.getLoginInfo.username,
password: this.getLoginInfo.password
});
im.login({
name: this.user.username,
password: this.user.password
});
this.serr(err);
im.login({
name: this.user.username,
password: this.user.password
});
this.serr(err);
im.login({
name: this.user.username,
password: this.user.password
});
im.login({
name: this.user.username,
password: this.user.password
});
flooim.qrlogin(opt)
二维码登录
Kind: static method of flooim
Param | Type | Description |
---|---|---|
opt | object |
|
opt.user_id | number |
用户ID |
opt.password | string |
密码 |
Example
flooim.tokenLogin(user_id, token)
token登录
Kind: static method of flooim
Param | Type | Description |
---|---|---|
user_id | number |
用户ID |
token | string |
Token |
Example
im.tokenLogin({
user_id: loginInfo.user_id,
token: loginInfo.token
});
flooim.idLogin(opt)
使用用户ID和密码登录
Kind: static method of flooim
Param | Type | Description |
---|---|---|
opt | object |
|
opt.user_id | number |
用户ID |
opt.password | string |
密码 |
Example
im.idLogin({
user_id: loginInfo.user_id,
password: loginInfo.password
});
flooim.isLogin() ⇒ boolean
是否已登录
Kind: static method of flooim
Returns: boolean
- 是否已登录
Example
const im = this.getIM();
return im && im.isLogin && im.isLogin();
flooim.on(options, ext)
事件监听
Kind: static method of flooim
Param | Type | Description |
---|---|---|
options | Event | Object.<Event , EventCallback > |
可以为事件名,也可以为事件名和事件回调 |
ext | EventCallback | undefined |
事件回调,只有options为事件名时需要设置 |
Example
const im = flooim(config);
im.on('event', (ret) => {
//do something with ret
})
// or
im.on({
eventName: (ret) => {
//do something with ret
},
...
})
this.requireMessage();
this.scroll();
this.$store.dispatch('forward/actionCancelForward', false);
this.$store.getters.im.on('onGroupMessage', (message) => {
this.reloadMessage(message);
});
this.$store.getters.im.on('onGroupMessageContentAppend', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageContentAppend(message);
this.calculateScroll(message);
}
}
});
this.$store.getters.im.on('onGroupMessageReplace', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageReplace(message);
this.scroll();
}
}
});
this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
this.queryingHistory = false;
this.$store.dispat...
this.requireMessage();
this.scroll();
this.$store.dispatch('forward/actionCancelForward', false);
this.$store.getters.im.on('onGroupMessage', (message) => {
this.reloadMessage(message);
});
this.$store.getters.im.on('onGroupMessageContentAppend', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageContentAppend(message);
this.calculateScroll(message);
}
}
});
this.$store.getters.im.on('onGroupMessageReplace', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageReplace(message);
this.scroll();
}
}
});
this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
this.queryingHistory = false;
this.$store.dispat...
this.requireMessage();
this.scroll();
this.$store.dispatch('forward/actionCancelForward', false);
this.$store.getters.im.on('onGroupMessage', (message) => {
this.reloadMessage(message);
});
this.$store.getters.im.on('onGroupMessageContentAppend', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageContentAppend(message);
this.calculateScroll(message);
}
}
});
this.$store.getters.im.on('onGroupMessageReplace', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageReplace(message);
this.scroll();
}
}
});
this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
this.queryingHistory = false;
this.$store.dispat...
this.requireMessage();
this.scroll();
this.$store.dispatch('forward/actionCancelForward', false);
this.$store.getters.im.on('onGroupMessage', (message) => {
this.reloadMessage(message);
});
this.$store.getters.im.on('onGroupMessageContentAppend', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageContentAppend(message);
this.calculateScroll(message);
}
}
});
this.$store.getters.im.on('onGroupMessageReplace', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageReplace(message);
this.scroll();
}
}
});
this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
this.queryingHistory = false;
this.$store.dispat...
this.requireMessage();
this.scroll();
this.$store.dispatch('forward/actionCancelForward', false);
this.$store.getters.im.on('onGroupMessage', (message) => {
this.reloadMessage(message);
});
this.$store.getters.im.on('onGroupMessageContentAppend', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageContentAppend(message);
this.calculateScroll(message);
}
}
});
this.$store.getters.im.on('onGroupMessageReplace', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageReplace(message);
this.scroll();
}
}
});
this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
this.queryingHistory = false;
this.$store.dispat...
this.requireMessage();
this.scroll();
this.$store.dispatch('forward/actionCancelForward', false);
this.$store.getters.im.on('onGroupMessage', (message) => {
this.reloadMessage(message);
});
this.$store.getters.im.on('onGroupMessageContentAppend', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageContentAppend(message);
this.calculateScroll(message);
}
}
});
this.$store.getters.im.on('onGroupMessageReplace', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageReplace(message);
this.scroll();
}
}
});
this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
this.queryingHistory = false;
this.$store.dispat...
this.requireMessage();
this.scroll();
this.$store.dispatch('forward/actionCancelForward', false);
this.$store.getters.im.on('onGroupMessage', (message) => {
this.reloadMessage(message);
});
this.$store.getters.im.on('onGroupMessageContentAppend', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageContentAppend(message);
this.calculateScroll(message);
}
}
});
this.$store.getters.im.on('onGroupMessageReplace', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageReplace(message);
this.scroll();
}
}
});
this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
this.queryingHistory = false;
this.$store.dispat...
this.requireMessage();
this.scroll();
this.$store.dispatch('forward/actionCancelForward', false);
this.$store.getters.im.on('onGroupMessage', (message) => {
this.reloadMessage(message);
});
this.$store.getters.im.on('onGroupMessageContentAppend', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageContentAppend(message);
this.calculateScroll(message);
}
}
});
this.$store.getters.im.on('onGroupMessageReplace', (message) => {
if (this.$refs.vMessages) {
let msg = this.$refs.vMessages.reverse().find((item) => item.message.id == message.id);
if (msg) {
msg.messageReplace(message);
this.scroll();
}
}
});
this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
this.queryingHistory = false;
this.$store.dispat...
flooim.off(options, ext)
取消监听
Kind: static method of flooim
Param | Type | Description |
---|---|---|
options | Event | Object.<Event , EventCallback > |
可以为事件名,也可以为事件名和事件回调 |
ext | EventCallback | undefined |
事件回调,只有options为事件名时需要设置 |
Example
const im = flooim(config);
im.off('events', (ret) => {
//do something with ret
})
// or
im.off({
eventName: (ret) => {
//do something with ret
},
...
})
const im = this.$store.getters.im;
if (!im) return;
im.off({
onGroupMessage: '',
onGroupMessageContentAppend: '',
onGroupMessageReplace: '',
onReceiveHistoryMsg: '',
onMessageStatusChanged: '',
onSendingMessageStatusChanged: '',
onMessageRecalled: '',
onMessageDeleted: '',
onMessageCanceled: ''
});
const im = this.$store.getters.im;
if (!im) return;
im.off({
onRosterMessage: '',
onRosterMessageContentAppend: '',
onRosterMessageReplace: '',
onReceiveHistoryMsg: '',
onMessageStatusChanged: '',
onSendingMessageStatusChanged: '',
onMessageRecalled: '',
onMessageDeleted: '',
onMessageCanceled: ''
});
const im = this.$store.getters.im;
if (!im) return;
im.off({
onGroupMessage: '',
onGroupMessageContentAppend: '',
onGroupMessageReplace: '',
onReceiveHistoryMsg: '',
onMessageStatusChanged: '',
onSendingMessageStatusChanged: '',
onMessageRecalled: '',
onMessageDeleted: '',
onMessageCanceled: ''
});
const im = this.$store.getters.im;
if (!im) return;
im.off({
onRosterMessage: '',
onRosterMessageContentAppend: '',
onRosterMessageReplace: '',
onReceiveHistoryMsg: '',
onMessageStatusChanged: '',
onSendingMessageStatusChanged: '',
onMessageRecalled: '',
onMessageDeleted: '',
onMessageCanceled: ''
});
flooim.logout()
退出账户
Kind: static method of flooim
Example
this.sdkok = false;
this.appid = newAppID;
this.saveAppId(this.appid);
const im = this.getIM();
im && im.logout && im.logout({ quitAllWeb: false });
this.initFlooIM();
this.waitForFlooReadyAndLogin(0);
flooim.setLogLevel(logLevel)
设置日志等级
Kind: static method of flooim
Param | Type | Description |
---|---|---|
logLevel | string |
SDK的日志等级, 默认为debug, 取值为 debug、info、warn、error 或 off, 其中off为不打印日志。 |
Example