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

@efox/chatroom

v1.24.2

Published

chatroom工具库

Downloads

15

Readme

聊天室封装简易sdk

创建实例(createChatroom)

import createChatroom from '@efox/chatroom'
const chatromm = await createChatroom(options)

请求参数:Object

| Name | Type | Description | | --------- | ----------------------- | --------------------------------------------------- | | hummer? | Hummer | 原始hummer(没传会自动创建) | | otp | string | 用户token(没传原始hummer时,必须传) | | appid? | string | 应用appid(没传原始hummer时,必须传) | | region? | string | 用户区域(没传原始hummer时,必须传) | | roomid? | string | 房间id(没传会自动创建) | | extListenEvents? | array | 补充监听事件列表 |

响应数据:Object

| Name | Type | Description | | --------- | ------ | --------------------------- | | chatromm | Object | 房间实例 |

实例属性(attributes)

const {roomid, root, hummer} = chatromm

| Name | Type | Description | | --------- | ----------------------- | --------------------------------------------------- | | roomid | string | 房间id | | hummer | object | 原始hummer | | root | object | 原始hummer创建的原始chatroom实例 |

发送消息(send)

chatromm.send({
    event: '',
    data: {
        content: ''
    }
})

请求参数:Object

| Name | Type | Description | | --------- | ----------------------- | --------------------------------------------------- | | event | string | 发送事件类型 | | data | Object | 发送数据 |

响应数据:Object

| Name | Type | Description | | --------------------- | -------------- | ---------- | | rescode | number | 0:表示成功 | | msg | string | 返回描述 |

发送消息事件类型

sendGroupMessage发送群组消息

请求参数:

| Name | Type | Description | | --------------------- | ----------------- | ----------------- | | content | string | 内容 | | kvExtra | {[k: string]: string} | 扩展字段key-value |

响应数据:

| Name | Type | Description | | --------------------- | ----------------- | ---------- | | rescode | number | 0:表示成功 | | msg | string | 返回描述 |

示例:

  const await res = chatromm.send({
    event: 'sendGroupMessage',
    data: {
        content,
        kvExtra
    }
  })

sendSingleUserMessage发送单播消息

请求参数:

| Name | Type | Description | | --------------------- | ----------------- | ----------------- | | content | string | 内容 | | receiver | string | 接收者uid | | kvExtra | {[k: string]: string} | 扩展字段key-value |

响应数据:

| Name | Type | Description | | --------------------- | -------------- | ---------- | | rescode | number | 0:表示成功 | | msg | string | 返回描述 |

示例:

  const await res = chatromm.send({
    event: 'sendSingleUserMessage',
    data: {
        content, receiver, kvExtra
    }
  })

sendTextChat发送公屏

请求参数:

| Name | Type | Description | | --------------------- | ----------------- | ----------------- | | chat | string | 内容 | | extra | string | | | kvExtra | {[k: string]: string} | |

响应数据:

| Name | Type | Description | | --------------------- | ----------------- | --------- | | rescode | number | 0:表示成功 | | msg | string | 返回描述 |

【注】 (1)新业务接入,扩展字段值请使用kvExtra,不要使用extra; (2)如果是需要与移动端sdk进行互通的老业务,需要使用extra的情形,请与移动端SDK进行互通联调;

示例:

  const await res = chatromm.send({
    event: 'sendTextChat',
    data: {
        chat, extra, kvExtra
    }
  })

订阅所有事件(subscribe)

const unsubscribe = chatromm.subscribe(({name, res}) => {
    console.log({
        name, res
    })
})
// 如果要取消该订阅
unsubscribe()

请求参数:Function 可以订阅多次,最多限制20次,每次的传入函数,会有以下对象数据:

| Name | Type | Description | | --------- | ----------------------- | --------------------------------------------------- | | name | string | 事件类型 | | res | Object | 返回数据 |

响应数据:Function

执行返回函数,可以取消该订阅

订阅后可以获取到的事件消息

接受事件类型,请参考以下文档中的接受消息部分中的事件名和返回数据

https://github.com/cherishman2005/hummer-js-sdk-api/blob/master/hummer3.0/chatroom/chatroom%E5%AF%B9%E5%A4%96%E6%8E%A5%E5%8F%A3.md

例如接收公屏消息(TextChat)

const unsubscribe = chatromm.subscribe(({name, res}) => {
    if (name === 'TextChat') {
        const {extra, uid, kvExtra} = res
        console.log(res)
    }
})

订阅所有消息(subscribeMsgs)

只订阅单播、群组、公屏三种消息事件

const unsubscribe = chatromm.subscribeMsgs(({name, res}) => {
    // 
})
// 如果要取消该订阅
unsubscribe()

请求参数:Function

| Name | Type | Description | | --------- | ----------------------- | --------------------------------------------------- | | name | string | 事件类型 | | res | Object | 返回数据 |

响应数据:Function 执行返回函数,可以取消该订阅

获取用户列表(getUsers)

请求参数:object

| Name | Type | Description | | --------------------- | ----------------- | ----------------- | | num? | number | 数量(默认10) | | pos? | number | 起始点(默认0) |

响应数据:string[]

| Name | Type | Description | | --------------------- | ----------------- | --------- | | uids | string[] | 用户列表 |

原始sdk链接

https://github.com/cherishman2005/hummer-js-sdk-api/blob/master/hummer3.0/chatroom/chatroom%E5%AF%B9%E5%A4%96%E6%8E%A5%E5%8F%A3.md