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

@medlinker/im-sdk

v0.7.0

Published

> TODO: description

Downloads

6

Readme

@medlinker/im-sdk

sdk 封装参考了koa的中件机制,当接收到服务端推送过来的一个websocket消息时,依次该消息会经过一系列的中间件最终将消息处理为一个对象供视图进行使用,sdk 内部已经集成了部分必要的中间件(详见:./src/middlewares 文件夹)

本 sdk 有一个配套的组件库(@medlinker/im-components)开箱即用,如果样式不能满足需要,也可以自定义组件,组件如何封装没有统一要求,可以参考@medlinker/im-components

使用

  1. 首先需要进行业务登录

    初始化 im 会使用.medlinker.com 域名下 cookie 进行登录,如果没有提前登陆 im 会初始化失败

  2. 初始化 im 实例
const im = new MedIm(
  {
    type: ConversationType.Group,
    from: {
      // 在步骤0中登陆的用户id
      id: loginUserId,
      reference: Reference.medlinker,
    },
    // 如果是群聊
    group: {
      id: groupId,
    },
  },
  {
    // 传入当前的环境的域名
    imApi: '//im-api-qa.medlinker.com',
    imGate: '//im-wss-qa.medlinker.com/gate',
  }
);
  1. 监听对应的事件
im.on(MedImEvent.sdkReady, () => {
  // im已经初始化完成,可以在这里拉取历史消息等
});
im.on(MedImEvent.receiveMessage, (message) => {
  // 接受到服务端推送的消息时调用
  console.log(message);
});
  1. 发送消息
// 3.1 创建对应消息的payload
const textPayload = createTextPayload({
  content: '发送的文本信息',
});

// 3.2 调用im实例上的createMessage,这个会使用初始化时候传入的登录用户和接受对象创建一个消息
const message = im.createMessage({
  text: textPayload,
});

// 3.3 调用im实例上的send方法,将消息发送出去
im.send(message).then((res) => {
  if (res) {
    // 发送成功
  } else {
    // 发送失败会返回null
  }
});