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 🙏

© 2025 – Pkg Stats / Ryan Hefner

webim-lib

v1.0.2

Published

1. 引入

Downloads

7

Readme

初始化及连接

  1. 引入

    通过标签方式直接引入

    <script src="/dist/bundle.js"></script>
    <!-- 
    #自动引入全局变量 webim
    #可自由选择 webim.WebIM/webim.WebRTC
    -->

    通过npm安装 npm i webim-lib

    import { WebIM , WebRTC } from 'webim-lib'
    • 其中 WebRTC 继承 WebIM ,包含 WebIM 完整实例功能
    • 为提高webrtc的兼容性,你可以自行引入 https://webrtc.github.io/adapter/adapter-latest.js
  2. 初始化

    const conn = new WebRTC( config )
    // const conn = new WebRTC( config )
    // config 可配置选项
    {
    	apiURL: "https://imapitest.wecloud.cn", //接口请求地址 | 必须
    	wsURL: 'wss://imapitest.wecloud.cn/ws',	//websocket URL | 必须
    	heartBeatWait: 15000,					//websocket心跳间隔时间
    	reConnectNumMax: '2',					//websocket 最大重连次数
    	reConnectTimeWait: 2000,				//websocket 重新连接等待时间
       sendMessageTimeout: 8000,			  	//websocket 发送消息超时时间
       videoConstraints:true,				   //video预设,默认为true
       audioConstraints:true					//audio预设,默认为true
       ...
    }
  3. 绑定回调事件

    conn.onClosed = function () { }
    conn.onTextMessage = function () { } 	//接收到文本消息时
    conn.onError = function () { }
       
    conn.onLocalStream = function (stream) { }	//可以用本地流时
    conn.onRemoteStream = function (stream) { }	//可以使用远端流时
    conn.onCall = function () { }			// 接收到被人呼叫时
    conn.onClientJoined = function () { }	//对方加入通话时
    conn.onRefuseAnswer = function () { } 	//对方拒绝通话邀请时
    conn.onClientLeave = function () { } 	//对方离开通话时
    ...
       
  4. 连接

    const option = {
        timestamp: 1635410291094,
        clientId: "44ds55224d4d",
        appKey: "ldZ3oal2LkthGhQp",
        sign:"95b885d82e4ab37e62bcdf3eee",
    } 
    conn.open(option)
  5. 关闭连接

    conn.close()

消息

  1. 文本消息

    const reqId = conn.createRequestId() //消息id,发送成功后会返回,可用于更新本地数据
    
    const msgBody = conn.creatMessage({
       reqId,
       type: 'text',
       msg:'hello!!!',
       toConversation:'44233d5s336ds333z'
       ext:{} //自定义扩展数据 
    })
    conn.send(msgBody).then( () => {} )

会话

  1. 创建会话

    const options = {
        name:'name', //会话名称
        clientIds:['clientA','clientB'] //会话中包含的用户,
        attributes:{}	//自定义属性
    }
    conn.createConversation(options).then((res)=>{ console.log(res) })
  2. 获取会话列表

    conn.getConversationList().then((res)=>{ console.log(res) })
  3. 设置会话状态

    const conversationIds = ['clientA']
    const state = false   //state 状态  true 显示, false隐藏
    conn.setConversationState(conversationIds,state).then(()=>{})
  4. 获取离线消息

    conn.getOfflineList().then((res)=>{ console.log(res) })
  5. 获取历史消息

    conn.getHistoryMsg(options).then((res)=>{ console.log(res) })
  6. 消息设为已读状态

    conn.setMessageRead(msgIds).then((res)=>{ console.log(res) })
  7. 消息设为已接收状态

    conn.setMessageReceived(msgIds).then((res)=>{ console.log(res) })
  8. 消息撤回

    conn.withdrawMessage(msgIds).then((res)=>{ console.log(res) })

RTC视频通话(1x1)

  1. 呼叫

    const option = {
        toClient:'5assd2s4w' //呼叫clientId
    }
       
    conn.call(option).catch((err)=>{ console.log(err) })
  2. 接听

    const option = {	//onCall回调会返回
        channelId:'4s53s2wews',	
        type:'video' // voice,video(默认)
    }
    conn.answer(option).catch((err)=>{ console.log(err) })
  3. 挂断

    conn.hangup().then(()=>{})
  4. 设置本地录像状态

conn.setVideoMute(true)	//true:关闭录视频,false:开启录视频
  1. 设置本地录音状态

    conn.setAudioMute(true) //true:关闭录音,false:开启录音		
  2. 切换摄像头

    // 'environment' 后置摄像头,user 前置
    conn.switchCamera('environment')  //( video constrains)
    
  3. 设置视频参数

    const options = {
        height: 400,
        width: 600
    }
    conn.applyVideoConstraints(options) //  (video constrains)

...

即时通讯官网

https://www.wecloud.cn/product/message.html

体验简易demo:https://imwebtest.wecloud.cn