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: 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;
this.saveLoginInfo({ username, password }, this.appid);
im.login({
  name: username,
  password: password
});
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(ex);
im.login({
  name: this.user.username,
  password: this.user.password
});
im.login({
  name: this.user.username,
  password: this.user.password
});
im.login({
  name: this.user.username,
  password: this.user.password
});
im.login({
  name: res.username,
  password: res.password
});

flooim.qrlogin(opt)

二维码登录

Kind: static method of flooim

Param Type Description
opt object
opt.user_id number 用户ID
opt.password string 密码

Example

console.log('登录了....');
_this.im.qrlogin({ password, user_id });
console.log('登录了....');
_this.im.qrlogin({ password, user_id });

flooim.tokenLogin(user_id, token)

token登录

Kind: static method of flooim

Param Type Description
user_id number 用户ID
token string Token

Example

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.getters.im.on('onGroupMessage', (message) => {
  this.reloadMessage(message);
});

this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
  this.queryingHistory = false;
  this.$store.dispatch('content/actionAppendMessage', {
    history: true,
    next
  });
  !this.getMessages.length && this.scroll();
});

this.$store.getters.im.on('onMessageStatusChanged', ({ mid }) => {
  console.log('Message status changed, mid: ', mid);
  this.requireMessage();
});

this.$store.getters.im.on('onSendingMessageStatusChanged', ({ status, mid }) => {
  console.log('Sending Message status changed to ', status, ' mid: ', mid);
  // this.requireMessage();
});

this.$store.getters.im.on('onMessageRecalled', ({ mid }) => {
  this.deleteMessage(mid);
});

this.$store.getters.im.on('onMessageDeleted', ({ mid }) => {
  this.deleteMessage(mid...
this.requireMessage();
this.scroll();

this.$store.getters.im.on('onGroupMessage', (message) => {
  this.reloadMessage(message);
});

this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
  this.queryingHistory = false;
  this.$store.dispatch('content/actionAppendMessage', {
    history: true,
    next
  });
  !this.getMessages.length && this.scroll();
});

this.$store.getters.im.on('onMessageStatusChanged', ({ mid }) => {
  console.log('Message status changed, mid: ', mid);
  this.requireMessage();
});

this.$store.getters.im.on('onSendingMessageStatusChanged', ({ status, mid }) => {
  console.log('Sending Message status changed to ', status, ' mid: ', mid);
  // this.requireMessage();
});

this.$store.getters.im.on('onMessageRecalled', ({ mid }) => {
  this.deleteMessage(mid);
});

this.$store.getters.im.on('onMessageDeleted', ({ mid }) => {
  this.deleteMessage(mid...
this.requireMessage();
this.scroll();

this.$store.getters.im.on('onGroupMessage', (message) => {
  this.reloadMessage(message);
});

this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
  this.queryingHistory = false;
  this.$store.dispatch('content/actionAppendMessage', {
    history: true,
    next
  });
  !this.getMessages.length && this.scroll();
});

this.$store.getters.im.on('onMessageStatusChanged', ({ mid }) => {
  console.log('Message status changed, mid: ', mid);
  this.requireMessage();
});

this.$store.getters.im.on('onSendingMessageStatusChanged', ({ status, mid }) => {
  console.log('Sending Message status changed to ', status, ' mid: ', mid);
  // this.requireMessage();
});

this.$store.getters.im.on('onMessageRecalled', ({ mid }) => {
  this.deleteMessage(mid);
});

this.$store.getters.im.on('onMessageDeleted', ({ mid }) => {
  this.deleteMessage(mid...
this.requireMessage();
this.scroll();

this.$store.getters.im.on('onGroupMessage', (message) => {
  this.reloadMessage(message);
});

this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
  this.queryingHistory = false;
  this.$store.dispatch('content/actionAppendMessage', {
    history: true,
    next
  });
  !this.getMessages.length && this.scroll();
});

this.$store.getters.im.on('onMessageStatusChanged', ({ mid }) => {
  console.log('Message status changed, mid: ', mid);
  this.requireMessage();
});

this.$store.getters.im.on('onSendingMessageStatusChanged', ({ status, mid }) => {
  console.log('Sending Message status changed to ', status, ' mid: ', mid);
  // this.requireMessage();
});

this.$store.getters.im.on('onMessageRecalled', ({ mid }) => {
  this.deleteMessage(mid);
});

this.$store.getters.im.on('onMessageDeleted', ({ mid }) => {
  this.deleteMessage(mid...
this.requireMessage();
this.scroll();

this.$store.getters.im.on('onGroupMessage', (message) => {
  this.reloadMessage(message);
});

this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
  this.queryingHistory = false;
  this.$store.dispatch('content/actionAppendMessage', {
    history: true,
    next
  });
  !this.getMessages.length && this.scroll();
});

this.$store.getters.im.on('onMessageStatusChanged', ({ mid }) => {
  console.log('Message status changed, mid: ', mid);
  this.requireMessage();
});

this.$store.getters.im.on('onSendingMessageStatusChanged', ({ status, mid }) => {
  console.log('Sending Message status changed to ', status, ' mid: ', mid);
  // this.requireMessage();
});

this.$store.getters.im.on('onMessageRecalled', ({ mid }) => {
  this.deleteMessage(mid);
});

this.$store.getters.im.on('onMessageDeleted', ({ mid }) => {
  this.deleteMessage(mid...
this.requireMessage();
this.scroll();

this.$store.getters.im.on('onGroupMessage', (message) => {
  this.reloadMessage(message);
});

this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
  this.queryingHistory = false;
  this.$store.dispatch('content/actionAppendMessage', {
    history: true,
    next
  });
  !this.getMessages.length && this.scroll();
});

this.$store.getters.im.on('onMessageStatusChanged', ({ mid }) => {
  console.log('Message status changed, mid: ', mid);
  this.requireMessage();
});

this.$store.getters.im.on('onSendingMessageStatusChanged', ({ status, mid }) => {
  console.log('Sending Message status changed to ', status, ' mid: ', mid);
  // this.requireMessage();
});

this.$store.getters.im.on('onMessageRecalled', ({ mid }) => {
  this.deleteMessage(mid);
});

this.$store.getters.im.on('onMessageDeleted', ({ mid }) => {
  this.deleteMessage(mid...
this.requireMessage();
this.scroll();

this.$store.getters.im.on('onGroupMessage', (message) => {
  this.reloadMessage(message);
});

this.$store.getters.im.on('onReceiveHistoryMsg', ({ next }) => {
  this.queryingHistory = false;
  this.$store.dispatch('content/actionAppendMessage', {
    history: true,
    next
  });
  !this.getMessages.length && this.scroll();
});

this.$store.getters.im.on('onMessageStatusChanged', ({ mid }) => {
  console.log('Message status changed, mid: ', mid);
  this.requireMessage();
});

this.$store.getters.im.on('onSendingMessageStatusChanged', ({ status, mid }) => {
  console.log('Sending Message status changed to ', status, ' mid: ', mid);
  // this.requireMessage();
});

this.$store.getters.im.on('onMessageRecalled', ({ mid }) => {
  this.deleteMessage(mid);
});

this.$store.getters.im.on('onMessageDeleted', ({ mid }) => {
  this.deleteMessage(mid...
this.$store.getters.im.on('onMentionMessage', (messages) => {
  const { from, config } = messages;
  const gid = this.getSid;
  const toUid = toNumber(messages.to);
  if (gid === toUid) {
    if (config && config.mentionList && config.mentionList.length) {
      // 如果有mention的
      const uid = this.$store.getters.im.userManage.getUid();
      const hasIndex = config.mentionList.findIndex((x) => x + '' === uid + '');
      if (hasIndex > -1) {
        const umaps = this.$store.getters.im.rosterManage.getAllRosterDetail();
        const str = umaps[from].username + ' 在群中提到了您!';
        this.mentionMessage = str;
      }
    }
    ////
  }
});

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({
  onRosterMessage: '',
  onReceiveHistoryMsg: '',
  onMessageStatusChanged: '',
  onMessageRecalled: '',
  onMessageDeleted: '',
  onMessageCanceled: ''
});
const im = this.$store.getters.im;
if (!im) return;

im.off({
  onRosterMessage: '',
  onReceiveHistoryMsg: '',
  onMessageStatusChanged: '',
  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();

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

© 2019-2023 美信拓扑 | 官网 该文件修订时间: 2023-06-17 16:34:49

results matching ""

    No results matching ""