npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

les-im-components

v1.1.56

Published

本组件用于连接Les的IM平台服务器,进行收发消息及相关功能的操作

Downloads

13

Readme

les-im-components

本组件用于连接Les的IM平台服务器,进行收发消息及相关功能的操作

npm install les-im-components

使用方法

import { LesPlatformCenter, LesConstants } from 'les-im-components';

//在需要连接的地方调用connect方法

//此处应注意,通过api登陆accountCenter获取id和token时,serviceId应为 les-im-{deviceId}
//例如deviceId为IOS,则serviceId应为 les-im-IOS,大小写敏感
//deviceId详见LesConstants.IMDevices
LesPlatformCenter.Inst.connect("websocket地址", userId, token, deviceId).then(() => {
    //连接成功的处理
  }).catch(code => {
    //连接错误,code为错误代码
    //具体代码查看LesConstants.ErrorCodes
  })
 

LesPlatformCenter.IMFunctions 下的所有方法是IM相关功能实现,具体使用方法详见注释.

//例如登录后设置im用户名

const name = "起个名字";

LesPlatformCenter.IMFunctions.setName(name).then(nameInfo => {
      console.log(`名称设置成功:${nameInfo.name}#${nameInfo.tag}`)
    }).catch(code => {
      //错误处理
      //code为错误代码
      //具体代码查看LesConstants.ErrorCodes
    })


//设置用户状态

const state = LesConstants.IMUserState.Busy;

LesPlatformCenter.IMFunctions.setState(state).then(code => {
        //设置成功
    }).catch(code => { 
        //错误处理
        //code为错误代码
    })

LesPlatformCenter.IMListeners 用于设置服务器通知消息处理函数,具体的函数参数都在注释中写明了

//例如 监听用户状态变化
//当用户状态发生变化时,会回调这个接口,只能监听到好友的状态变化,例如上下线,切换为忙碌状态等
LesPlatformCenter.IMListeners.onIMUserStateChanged = (user, onlineState, state) => {
    //user -- 用户信息
    //onlineState -- 当前在线状态 IMUserOnlineState
    //state -- 当前状态 IMUserState

    //...相应处理
};

关于参数中的数据类

在处理回调或者调用某些功能时,返回的数据类型是一个类,例如给指定用户发送消息

LesPlatformCenter.IMFunctions.sendMessage(123, '测试消息').then(message=>{
    //此处的messsage是一个LesIMTimelineData 类型(方法注释中有标注)
}).cache(code=>{
    //错误处理...
})

所有LesIM开头的类型,都是对应的protobuf类型,可以在git上的项目 MetaVirus-ProtoBuf 中,protos/LesPlatform/Message或者protos/LesPlatform/Message/data目录中找到同名文件。

例如 LesIMTimelineData 类型,在项目的protos/LesPlatform/Message/data中,可以找到 LesIMTimelineData.proto文件

文件定义如下:

message PBLesIMTimelineData {
    optional int64 timelineId = 1;
    optional int64 messageId = 2;
    optional int64 senderId = 3;
    optional int64 recipientId = 4;
    optional int32 messageType = 5;
    optional int64 groupId = 6;
    optional int64 timestamp = 7;
    optional int32 contentType = 8; 
    optional string content = 9;
}

在javascript中,可以直接读取变量值

例如发送消息方法

LesPlatformCenter.IMFunctions.sendMessage(123, '测试消息').then(message=>{
    //此处的messsage是一个LesIMTimelineData 类型(方法注释中有标注)

    //类型中的成员变量,都可以通过 get + protobuf定义文件中的名称 进行获取

    //例如 protobuf 文件中定义了 timelineId 变量
    //需要注意的是 protobuf 中定义的变量名,除了首字母大写,其他都是小写
    //获取timelineId变量值的方法名就是  get + Timelineid ()
    const timelineId = message.getTimelineid();
    const senderId = message.getSenderid();
    const contentType = message.getContenttype();
    const content = message.getContent();

})