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

@voyage-fe/helmet-video

v1.2.1

Published

安全帽视频通话SDK

Downloads

21

Readme

安全帽 SIP 视频通话 SDK

1、引言

1.1 概述

Sip 视频通话是引用 SIP.js 实现的一种视频通话技术,适用于支持 webrtc 的浏览器(ie11 及之前的版本不支持 webrtc)进行视频通话。SIP.js 是基于 JavaScript 编写的功能齐全的 SIP 堆栈。借助 SIP.js,我们可以利用 webrtc 的功能实现语音通话和视频通话,轻巧且易于使用。

1.2 在线调试(视频通话)demo 测试地址

  • 打开测试地址

    视频通话demo

  • 输入管理员账号、管理员密码及安全帽设备 ID(确保准确性)

  • 点击呼叫即可进行视频通话

1.3 其他

部分浏览器版本不支持 webrtc 通话,如若通话失败,可通过以下地址检测浏览器是否支持;

检测地址

2、前端开发指南

2.1 引入 SDK

这里我们提供了 3 种引入方式,分别为 commonjs、esm、cdn 等方式

  • commonjs、esm 第一步安装 sdk

    npm install @voyage-fe/helmet-video
  • commonjs 模块引入

    const HelmetVideo = require('@voyage-fe/helmet-video')
  • esm 模块引入

    import HelmetVideo from '@voyage-fe/helmet-video'
  • 通过 cdn 引入

    <script src="https://unpkg.com/@voyage-fe/helmet-video/dist/helmet-video.umd.js"></script>

    引入成功后 HelmetVideo 会挂载到 window 上

2.2 实现安全帽视频通话

  • HelmetVideo 类型说明
// 回调函数,成功失败都会触发回调
/** 错误码
 *  0: 成功
 *  1: 未知错误
 *  1000: 配置初始化失败
 *  1001: 用户代理注册失败
 *  1002: 通话连接失败
 *  1003: WebRTC错误
 *  1004: 账户超过最大登录限制
 */
type CallbackFn = (ret: { type: 'success' | 'fail'; message: string; code: number }) => void

// 类初始实例化参数
interface InitPara {
  videoEl: HTMLVideoElement // 视频元素
  callback?: CallbackFn // 回调函数 非必传
}

// 发起呼叫时配置参数
interface CallConfig {
  deviceId: string // 安全帽设备 ID
  userName: string // 管理员账号
  password: string // 管理员密码
}

// HelmetVideo 类
declare class HelmetVideo {
  callback?: CallbackFn
  constructor({ videoEl, callback }: InitPara)
  // 发起呼叫
  handleCall(config: CallConfig): Promise<void>
  // 挂断通话
  hangup(): void
}
  • 初始化 HelmetVideo (以 vue3 为例)

    <template>
      <video ref="videoRef" class="w-full h-full"></video>
    </template>
    <script setup lang="ts">
      import HelmetVideo from '@voyage-fe/helmet-video'
      import type { CallbackFn } from '@voyage-fe/helmet-video'
    
      const videoRef = ref(null as unknown as HTMLVideoElement)
    
      let helmetVideo: HelmetVideo
    
      function initHelmetVideo() {
        const callback: CallbackFn = ret => {
          status.value = ret.type
          if (ret.type === 'fail') {
            // do something
          }
        }
    
        const config = {
          videoEl: videoRef.value,
          callback,
        }
    
        helmetVideo = new HelmetVideo(config)
      }
    
      onMounted(() => {
        initHelmetVideo()
      })
    </script>
  • 实现呼叫和挂断

    import type { CallConfig } from '@voyage-fe/helmet-video'
    
    // 发起呼叫
    async function handleCall(config: CallConfig) {
      await helmetVideo.handleCall(config)
    }
    
    // 挂断通话
    async function hangup() {
      helmetVideo.hangup()
    }

2.3 demo 样例源码

详见 demo 测试地址 右键点击查看页面源码