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 🙏

© 2026 – Pkg Stats / Ryan Hefner

easemob-websdk

v5.1.2

Published

High-performance, type-safe, extensible instant messaging SDK

Readme

环信 Web IM SDK

easemob-websdk 是面向 Web 应用的 TypeScript IM SDK,提供连接管理、消息、会话、联系人、群组、聊天室、用户资料、在线状态和推送设置等类型安全的 API。

安装

npm install easemob-websdk

发布包同时支持 ESM 和 CommonJS。可从主入口导入完整 SDK,也可从 Manager 子路径导入,以便业务构建工具移除未使用的 Manager 代码。

快速开始

使用应用所需的 Manager 初始化客户端,再使用由应用服务端签发的用户 Token 登录:

import { ChatClient, ChatManager } from 'easemob-websdk';

const client = ChatClient.init({
  appKey: 'your-org#your-app',
  managers: [ChatManager],
});

client.addEventHandler('connection', {
  onConnected: () => {
    console.log('connected');
  },
  onDisconnected: event => {
    console.warn('disconnected', event.reason);
  },
});

await client.login({
  userId: 'user-id',
  token: 'user-token',
});

登录成功后可发送单聊文本消息:

const message = client.chatManager.createTextMessage({
  conversationId: 'peer-user-id',
  conversationType: 'singleChat',
  content: 'Hello from Easemob',
});

await client.chatManager.sendMessage(message);

Manager 子路径导入

import { ChatClient } from 'easemob-websdk';
import { ChatManager } from 'easemob-websdk/managers/chat';
import { GroupManager } from 'easemob-websdk/managers/group';

const client = ChatClient.init({
  appKey: 'your-org#your-app',
  managers: [ChatManager, GroupManager],
});

可用的 Manager 子路径:

  • easemob-websdk/managers/chat
  • easemob-websdk/managers/chat-thread
  • easemob-websdk/managers/chatroom
  • easemob-websdk/managers/contact
  • easemob-websdk/managers/group
  • easemob-websdk/managers/presence
  • easemob-websdk/managers/push
  • easemob-websdk/managers/user-info

浏览器 script 标签

未使用打包工具的 Web 应用可从 CDN 加载 IIFE bundle,加载后的全局变量为 IMSDK:

<script src="https://unpkg.com/easemob-websdk@latest/bundle/im-sdk-web.iife.js"></script>
<script>
  const client = IMSDK.ChatClient.init({
    appKey: 'your-org#your-app',
    managers: [IMSDK.ChatManager],
  });
</script>

错误处理

所有公开异步 API 都会 reject SDKError 子类。请根据稳定的 SDK 错误码处理异常,不要解析错误文案:

import { isSDKError } from 'easemob-websdk';

try {
  await client.login({ userId: 'user-id', token: 'user-token' });
} catch (error) {
  if (isSDKError(error)) {
    console.error(error.code, error.message, error.details);
  }
}

安全建议

  • 从应用服务端获取用户 Token,不要把 App 凭据或长期有效 Token 写入浏览器代码。
  • 不要在业务日志中输出 Token、授权请求头或消息正文。
  • 按照应用自身的安全策略保存和刷新 Token。

资源