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

aliyun-voip-web-sdk

v1.9.4

Published

阿里云 融合通信 VoIP SDK

Downloads

36

Readme

Aliyun VoIP Web SDK

阿里云融合通信voip-web-sdk,提供基于WebRTC适用于浏览器VoIP2PSTN或VoIP2VoIP通话场景的SDK。

接入可参考demo: https://github.com/pianzuozj/voip-web-demo

为保证稳定性,建议使用最新版chrome使用该功能

Status

NPM version

Installation

You can install it as dependency with npm/cnpm or yarn.

$ # save into package.json dependencies with -S
$ npm install aliyun-voip-web-sdk -S

$ # you can use cnpm for fast install
$ cnpm install aliyun-voip-web-sdk -S

$ # use yarn for install
$ yarn add aliyun-voip-web-sdk

快速开始

一、接入前准备

客户端需要从阿里云申请融合通信账号后才能接入,为了保证安全性,融合通信SDK通过服务端下发的临时token作为身份标识与服务进行交互。临时token可通过融合通信服务pop接口从阿里云获得(详见服务端接入文档),并且具有时效性。SDK在token即将失效或其他需求而需要更新token时,会通过回调通知接入方,接入方需自行实现接口获取最新token并传递给SDK。

WebSDK交互流程

二、快速开始

  • 创建实例
import {
    AlicomRTC, // AlicomRTC实例
    Errors, // 错误码
} from 'aliyun-voip-web-sdk'

/**
 * 创始实例
 */
var rtc = new AlicomRTC()
/**
 * 是否允许日志上传 默认不上传
 * @param enable true 上传日志  false 取消上传日志
 */

setUploadEnable(enable)
/**
 * 设置服务监听
 */
rtc.setServiceListener({
  /**
   * 服务连接成功,当前处于可用状态
   */
  onServiceAvailable: function () {
    // 此时可以开始呼叫操作
  },

  /**
   * 服务连接失败、或者连接断开了,当前处于不可用状态,服务正在销毁。
   * @param errCode {number} 错误码
   * @param errMsg {string} 错误描述
   */
  onServiceUnavailable: function (errCode, errMsg) {
  },

  /**
   * 服务闲时
   * @param errCode {number} 错误码
   * @param errMsg {string} 错误描述
   */
  onServiceIdle: function (errCode, errMsg) {
  },

  /**
   * 作为被叫,收到点对点音频来电
   * @param call {Call} 表示这通来电的call实例
   */
  onReceivingAudioCall: function(call) {
    // todo: 已有通话的情况下拒绝新呼入,或是挂断当前通话接听
  },
})

/**
 * 可选,设置默认的呼叫超时时间
 */
// rtc.setDefaultCallTimeout(30)
  • 连接服务
/**
 * 使用RtcId初始化AlicomRTC实例
 */
rtc.initWithRtcId('RTCID', {
  updateToken: function (tokenHandler) {
    var token = {} // todo: 通过服务端接口获取Token
    tokenHandler.setToken(token)
  }
})
  • 始初化通话实例 当ServiceListener中的onServiceAvailable回调被唤起时,表示服务已经连接成功,此时可以开始创建VoIP2PSTN通话实例,设置并开始通话:
/**
 * 创建VoIP2Pstn的Call实例,每一次通话都需要生成一个Call实例
 */
var pstnCall = rtc.createVoIP2PstnCall('被叫号显', '被叫号码')

/**
 * 创建VoIP2VoIP的Call实例,每一次通话都需要生成一个Call实例
 */
var voipCall = rtc.createVoIP2VoIPCall('被叫RtcID')

/**
 * 开启服务端录音(可选)
 */
pstnCall.setServerRecordEnabled(true)

/**
 * 本地禁音(可选)
 */
pstnCall.muteLocalAudio()

/**
 * 本地取消禁音(可选)
 */
pstnCall.unmuteLocalAudio()

/**
 * 发送dtmf (只能是0-9、*、#组成的字符串,最大长度不超过32位)
 */
pstnCall.sendDtmfData(dtmf)

/**
* 返回当前通话的channelId
*/
getChannelId(): string
  • 通话状态管理
/**
 * 设置Call状态监听
 */
pstnCall.setCallListener({
  /**
   * 电话已通知到被叫方,被叫振铃中
   * @param talk {Talk} 通话对象
   */
  onCalleeRinging: function (talk) {},

  /**
   * 被叫已接听电话,正在连接中
   * @param talk {Talk} 通话对象
   */
  onCalleeConnecting: function (talk) {},

  /**
   * 电话拨通了可以正常通话了。被叫已接听
   * @param talk {Talk} 通话对象
   */
  onActive: function (talk) {},

  /**
   * 对端传来DTMF信息,每次回调只传入一个字符,如果是一连串输入的话则会多次回调,需要接入方自行根据时间戳处理
   * @param dtmf {string} 对端传入的DTMF信息
   * @param timestamp {number} 时间戳
   * @param talk {Talk} 通话对象
   */
  onDtmfData: function (dtmf, timestamp, talk) {},
})
  • 主叫开始呼叫 / 被叫开始接听
pstnCall.start()
  • 停止呼叫/通话
pstnCall.stop()
  • 销毁实例
rtc.destroy()

三、常见错误码

| 错误码 | 数值 | 原因 | | --- | --- | --- | | ERROR_MQTT_CONNECT_FAIL | 1000100 | mqtt连接失败 | | ERROR_UPLOAD_TOKEN_FAIL | 1000104 | token上传失败 | | ERROR_LOCAL_STOP | 2000000 | 本地主动挂断 | | ERROR_REMOTE_HANGUP | 2000099 | 对端主动挂断 | | ERROR_CALL_SELF | 2000100 | 拨打自己 | | ERROR_CALL_EMPTY | 2000101 | 拨打电话为空 | | ERROR_CALLEE_ALERTING_TIMEOUT | 2000103 | 被叫时,振铃超时 | | ERROR_REMOTE_REFUSE | 2000106 | 主叫时,对端拒绝应答 | | ERROR_REMOTE_CANCEL | 2000107 | 被叫时,对端取消呼叫 | | ERROR_NO_ANSWER | 2000108 | 被叫无人接听 | | ERROR_SERVICE_UNAVAILABLE | 2000113 | AlicomRTC服务不可用 | | ERROR_LOCAL_DESTROY | 2000116 | 本地主动销毁服务 | | ERROR_TIME_OUT | 2000102 | joinChannel超时 | | ERROR_NETWORK_INVALID | 2000121 | 网络异常 | | ERROR_MICROPHONE_NO_PERMISSION | 2000130 | 麦克风无权限 | | ERROR_MICROPHONE_NO_DEVICE | 2000135 | 没有麦克风设备 | | ERROR_MICROPHONE_NOT_ALLOWED | 2000136 | 浏览器不允许使用麦克风 | | ERROR_MICROPHONE_NOT_READABLE | 2000137 | 系统禁用麦克风或者麦克风被占用 | | ERROR_SERVER_BASE | 3000000 | 服务端返回业务异常的错误基准 | | ERROR_SERVER_KICKED | 3110000 | 账号被登录或被踢 | | ERROR_SERVER_UNAVAILABLE | 3110001 | 服务异常 | | ERROR_MEDIA_BASE | 4000000 | 媒体sdk返回异常的错误基准 |

License

The MIT License