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

dd-lv-interaction-paas-jssdk

v0.0.1

Published

统一 LIVE INTERACTION SDK

Downloads

3

Readme

钉钉直播互动JSSDK介入文档

环境配置

  • 使用 npm 或 yarn 安装dd-lv-interaction-paas-jssdk
npm install --save dd-lv-interaction-paas-jssdk
yarn add dd-lv-interaction-paas-jssdk

工程接入

公共部分

  • 引入interactionSdk

    import { interactionSdk } from 'dd-lv-interaction-paas-jssdk';
  • 登录认证

    const Setting = { /* content */ }
    
    interactionSdk.getSettingService().set(Setting);
    
    interactionSdk.getAuthService().login();

    其中setting内容如下:

      interface Setting {
        environment: 0, // 环境
        wsUrl: string; // websocket url
        appKey: string; // 应用key IM_PAAS分配给应用的key
        mediaHost: string; // 多媒体上传服务器地址
        deviceId: string; // 设备唯一id
        appName?: string; // app_name 应用名称
        appVersion?: string; // 应用版本号
        appLocale?: string; // App 语言区域(默认zh_CN)
        osName?: string; // 操作系统名称,如Win、macOS、iOS、Android等
        osVersion?: string; // 操作系统版本
        deviceName?: string; // 设备名称
        deviceType?: string; // 设备型号
        deviceLocale?: string; // 设备语言(默认zh_CN)
        timeZone?: string; // time_zone 时区(默认Asia/Shanghai)
        subscribeServerPush?: string // subscribe-server-push header
        log: ILogConfig; // log回调
        authTokenCallback(): Promise<Token>; // on_callback 获取登录token的回调函数(注意需要做成异步操作,不能有阻塞)
      };
    
      interface ILogConfig {
        info(...args: any[]): void;
        error(...args: any[]): void;
      }

服务部分

互动API服务

使用interactionSdk.getInteractionService()获取互动API服务实例。

在JSSDK层面,各个实例是单例的。

  • 进入房间
      iinteractionSdk
        .getInteractionService()
        .enterRoom({
          roomId: 'roomId',
          nick: 'nickname'
        }).then(res => {
          if (res.success) console.log('进入房间成功')
          else throw new Error('res error')
        }).catch(err => {
          console.error(err, '进入房间失败')
        })
  • 查询房间详情
      interactionSdk
        .getInteractionService()
        .getRoomDetail({
          roomId: 'roomId'
        }).then((res) => {
          if (res.roomDetailVO) console.log('查询房间信息成功')
          else throw new Error('res error')
        }).catch(err => {
          console.error(err, '查询房间信息失败')
        })
  • 发布房间公告
     interactionSdk
       .getInteractionService()
       .publishRoomNotice({
         roomId: 'roomId',
         notice: '房间公告'
       }).then((res) => {
         if (res.success) console.log(`公告设置成功`)
         else throw new Error('res error')
       }).catch(err => {
         console.error(err, '公告设置失败')
       })
  • 离开房间
     interactionSdk
       .getInteractionService()
       .leaveRoom({
         roomId: 'roomId'
       }).then((res) => {
         if (res.success) console.log(`离开房间成功`)
         else throw new Error('res error')
       }).catch(err => {
         console.error(err, '离开房间失败')
       })
  • 点赞
     interactionSdk
       .getInteractionService()
       .sendLikesMsg({
         roomId: 'roomId',
         count: 1 // 允许几秒内发送一次弹幕
       }).then((res) => {
         if (res.interval || res.interval === 0) console.log('点赞成功')
         else throw new Error('res error')
       }).catch(err => {
         console.error(err, '点赞失败')
       })
  • 发文本消息
     interactionSdk
       .getInteractionService()
       .sendCommentMsg({
         roomId: 'roomId',
         content: '消息内容',
         type: 1, // 弹幕的类型,比如普通弹幕、超级弹幕,由调用方决定,服务端透传
         extension: {}
       }).then((res) => {
         if (res.commentId) console.log('消息发送成功')
         else throw new Error('res error')
       }).catch(err => {
         console.error(err, '消息发送失败')
       })
  • 发自定义消息
     interactionSdk
       .getInteractionService()
       .sendCustomMsg({
         roomId: 'roomId',
         subType: 100001,
         body: '消息内容', // 消息子类型,业务方决定
         receivers: [], // 接受者,如果不传默认给房间内全部在线用户广播
         priority: 0 // 自定义消息的优先级, 目前只支持高中低三个, 对应100:高, 0:中, -100低, 不传默认为0, 即中优先级
       }).then((res) => {
         if (res.messageId) console.log('发送消息成功')
         else throw new Error('res error')
       }).catch(err => {
         console.error(err, '发送消息失败')
       })
  • 查询消息
     interactionSdk
       .getInteractionService()
       .getRoomDetail({
         roomId: 'roomId'
       }).then((res) => {
         if (res.messages) {
           console.log('查询消息成功')
           res.messages.forEach(item => {
             // 部分信息
             console.log(`id: ${item.commentId}, nick: ${item.nick}, content: ${item.content}`)
           })
         } else throw new Error('res error')
       }).catch(err => {
         console.error(err, '查询消息失败')
       })

事件服务

使用interactionSdk.getEventService()获取事件实例。

  • 注册监听事件
interactionSdk.getEventService().register((eventName, data) => {
  /* do something */
})
  • 事件列表
enum EventNameEnum {
  PaaSConnectionChanged = 'paas.connection.changed', // 登录状态
  PaaSLiveRoomEnter = 'paas.live.room.enter', // 进入房间状态
  PaaSLiveRoomOlineCount = 'paas.live.room.onlinecount', // 在线人数变更
  PaaSLiveRoomNotice = 'paas.live.room.notice', // 设置公告
  PaaSLiveRoomComment = 'paas.live.room.comment', // 发布消息
  PaaSLiveRoomLike = 'paas.live.room.like', // 收到点赞
  PaaSLiveRoomCustomMessage = 'paas.live.room.customMessage', // 发布自定义消息
}
  • 事件解绑
interactionSdk.getEventService().unRegister()

浏览器环境要求

jssdk 对浏览器环境有一定的兼容性要求,主要依赖是对 websocket 的兼容性要求。兼容性参考表如下:

| 主流浏览器 | 最低版本要求 | | :-------------- | :----------- | | Chrome | 4 ~ 88 + | | Firefox | 11 ~ 85 + | | IE | 10 + | | Edge | 12 ~ 88 + | | Opera | 12.1 ~ 72 + | | Safari | 5 ~ 13.1 + | | Android Browser | 89 + | | Safari for iOS | 4.2 ~ 13.7 + |

更多兼容性请参考:https://caniuse.com/?search=websocket