flooim
flooim
flooim.flooim(config) ⇒ object
InitializationSDK
Kind: static method of flooim
Returns: object
- flooim object
Param | Type | Description |
---|---|---|
config | object |
SDK initialization settings |
config.appid | string |
APPID |
config.ws | boolean |
Whether the connection address is prefixed with ws/wss: ture - the connection address is prefixed with ws or wss; false - the connection address is prefixed with http/https |
config.autoLogin | boolean |
Whether to login automatically |
config.dnsServer | string | undefined |
DNS server address, can be empty, default https://dns.lanyingim.com/v2/app_dns |
config.logLevel | string |
The log level of the SDK, the default is debug, and the value can be debug, info, warn, error or off, where off means no log is printed. |
Example
const config = {
// dnsServer: "https://dns.lanyingim.com/v2/app_dns",
appid: "YOUR_APP_ID",
ws: false, // The uniapp version needs to be set to true, the web version needs to be set to 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)
Login
Kind: static method of flooim
Param | Type | Description |
---|---|---|
opt | object |
|
opt.name | string |
Username |
opt.password | string |
Password |
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)
QR code login
Kind: static method of flooim
Param | Type | Description |
---|---|---|
opt | object |
|
opt.user_id | number |
User ID |
opt.password | string |
Password |
Example
flooim.tokenLogin(user_id, token)
token login
Kind: static method of flooim
Param | Type | Description |
---|---|---|
user_id | number |
User ID |
token | string |
Token |
Example
im.tokenLogin({
user_id: loginInfo.user_id,
token: loginInfo.token
});
flooim.idLogin(opt)
Login with user ID and password
Kind: static method of flooim
Param | Type | Description |
---|---|---|
opt | object |
|
opt.user_id | number |
User ID |
opt.password | string |
Password |
Example
im.idLogin({
user_id: loginInfo.user_id,
password: loginInfo.password
});
flooim.isLogin() ⇒ boolean
Logged in or not
Kind: static method of flooim
Returns: boolean
- Logged in or not
Example
const im = this.getIM();
return im && im.isLogin && im.isLogin();
flooim.on(options, ext)
Event listening
Kind: static method of flooim
Param | Type | Description |
---|---|---|
options | Event | Object.<Event , EventCallback > |
Can be event name, and also event name plus event callback |
ext | EventCallback | undefined |
Event callback, only required if options is set as event name |
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)
Unlisten
Kind: static method of flooim
Param | Type | Description |
---|---|---|
options | Event | Object.<Event , EventCallback > |
Can be event name, and also event name plus event callback |
ext | EventCallback | undefined |
Event callback, only required if options is set as event name |
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: '',
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: '',
onMessageRecalled: '',
onMessageDeleted: '',
onMessageCanceled: ''
});
flooim.logout()
Log out
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)
set log level
Kind: static method of flooim
Param | Type | Description |
---|---|---|
logLevel | string |
The log level of the SDK, the default is debug, and the value can be debug, info, warn, error or off, where off means no log is printed. |
Example