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

sip-mix-agora-web

v2.0.2

Published

Sip SDK for Agora web SDK access call platform

Downloads

32

Readme

[TOC]

1 SIP-MIX-SDK 说明

SIP-MIX-SDK 基于JsSIP封装,用于和ACD进行信令交互,支持Agora SDK媒体协商方式。

2 API 说明

2.1 获取单例

获取SipMix类单例
@param domain     服务器域名或IP
@param port       服务器端口,默认5049
@param path       服务路径,默认webcall
@returns {SipMix} 返回SipMix实例

static SipMix.getInstance({
    domain: string,
    port: number = 5049,
    path: string = 'webcall',
}) : SipMix

注: 
1、如果不需要单例,也可以直接new SipMix对象,构造函数参数一致。
2、浏览器音视频通话需要HTTPS支持,如果没有证书可能会被浏览器拦截请求,请保证环境正常。

2.2 销毁单例

移除事件监听,销毁SipMix类单例
static SipMix.destroyInstance() : void

2.3 创建服务代理对象

创建SIP UA,进行服务器连接。(如开启注册模式,则在连接服务器后开始SIP注册)
@param deviceId     设备ID/主叫号码/分机号码,默认'H5User'
@param password     设备密码,选填
@param register     是否开启SIP 注册模式。默认false
@param debug        是否打开debug模式。默认false

sipMix.start({
    deviceId: string = 'H5User', 
    password: string, 
    register: boolean = false, 
    debug: boolean = false
}) : void

注:
1、调用后会触发connecting、connected、disconnected等事件
2、如果register为true,可能触发registered、registrationFailed等事件

2.4 呼叫号码

给被叫号码打电话
@param target         被叫号码
@param video          是否支持视频,默认为true
@param audio          是否支持音频,默认为true
@param extraHeaders   信令扩展头,在SIP消息头部添加的扩展头,部分业务需要。
@param token          用于向第三方鉴权。
@param userToUserData 透明参数,用于将参数携带到被叫方。
@param videoCodec     用于告知媒体服务器当前视频编码格式

sipMix.call({
    target: string, 
    video: boolean = true, 
    audio: boolean = true, 
    extraHeaders: array = [], 
    token: string, 
    userToUserData: string,
    videoCodec: string = 'H264'
}) : void

注:
1、token用于呼叫时由业务系统带入,ACD拿到后再到业务系统侧鉴权
2、后续可能会触发newSession、remoteRing、accepted、confirmed、end、failed等事件

2.5 发送会话内消息

通话过程中发送会话内消息。
@param sessionId   会话ID,多会话实例时需要传递,单会话实例时,可以不传,SDK自行判断会话实例。
@param contentType 消息类型
@param content     消息体

sipMix.sendInfo({
    sessionId: string,
    contentType: string = 'application/json',
    content: string | object
}) : void

注:
1、content为object时,SDK会使用JSON.stringify转换成字符串发送。

2.6 发送DTMF拨号

通话过程中发送二次拨号,可用于IVR菜单导航输入等。
@param sessionId   会话ID,多会话实例时需要传递,单会话实例时,可以不传,SDK自行判断会话实例。
@param tones       拨号字符串,如: '1234#', 1

sipMix.sendDTMF({
    sessionId: string,
    tones: string | number
}) : void

2.7 挂机

通话挂机。
@param sessionId   会话ID,多会话实例时需要传递,单会话实例时,可以不传,SDK自行判断会话实例。

sipMix.hangup({
    sessionId: string
}) : void

2.8 指定媒体SDK AppID

当平台配置多个媒体SDK AppID,可以指定某一个AppID做特殊处理。不调用时,使用平台默认媒体AppID。
@param appId   平台配置的某个媒体SDK AppId。

sipMix.setMediaSDKAppId( appId: string ) : void

3 事件说明

3.1 事件统一调用方式

@param eventName 事件名称
@param callback  事件处理回调

sipMix.on(eventName: string, callback: function)

3.2 事件回调

3.2.1 connecting

服务器连接中,调用start方法后触发
connecting () : void

3.2.2 connected

服务器已连接
connected () : void

3.2.3 disconnected

服务器连接断开
disconnected () : void

3.2.4 registered

注册成功,仅在start 参数中register参数为true时会触发
registered () : void

3.2.5 registrationFailed

注册失败,仅在start 参数中register参数为true时会触发
@param cause 原因

registrationFailed (cause: string) : void

注:
1、Failure and End Causes: https://jssip.net/documentation/3.10.x/api/causes/

3.2.6 unregistered

注册后注销,仅在start 参数中register参数为true时会触发
@param cause 原因

unregistered (cause) : void

注:
1、Failure and End Causes: https://jssip.net/documentation/3.10.x/api/causes/

3.2.7 newSession

产生新的会话实例
@param sessionId         SDK区分不同会话的sessionId
@param uri               被叫号码SIP URI, 如: sip:[email protected]:5049
@param userNumber        被叫号码,如: 0123456789

newSession ({
    sessionId: string,
    uri: string,
    userNumber: string,
}) : void

3.2.8 remoteRing

远端振铃
@param sessionId         SDK区分不同会话的sessionId
@param uri               被叫号码SIP URI, 如: sip:[email protected]:5049
@param userNumber        被叫号码,如: 0123456789
@param callId            平台callId
@param sdkParams         媒体SDK的参数
@param sdkParams.appId   appId
@param sdkParams.channel channelId Or roomId
@param sdkParams.userId  uid Or userId
@param sdkParams.token   token Or userSig

remoteRing ({
    sessionId: string,
    uri: string,
    userNumber: string,
    callId: string,
    sdkParams: {
        appId: string,
        channel: string,
        userId: string,
        token: string
    }
}) : void

3.2.9 accepted

收到远端应答信令
@param sessionId         SDK区分不同会话的sessionId
@param uri               被叫号码SIP URI, 如: sip:[email protected]:5049
@param userNumber        被叫号码,如: 0123456789
@param callId            平台callId
@param sdkParams         媒体SDK的参数
@param sdkParams.appId   appId
@param sdkParams.channel channelId Or roomId
@param sdkParams.userId  uid Or userId
@param sdkParams.token   token Or userSig

accepted ({
    callId: string,
    sessionId: string,
    uri: string,
    userNumber: string,
    sdkParams: {
        appId: string,
        channel: string,
        userId: string,
        token: string
    }
}) : void

3.2.10 confirmed

本地确认会话建立
@param sessionId         SDK区分不同会话的sessionId
@param uri               被叫号码SIP URI, 如: sip:[email protected]:5049
@param userNumber        被叫号码,如: 0123456789
@param callId            平台callId
@param sdkParams         媒体SDK的参数
@param sdkParams.appId   appId
@param sdkParams.channel channelId Or roomId
@param sdkParams.userId  uid Or userId
@param sdkParams.token   token Or userSig

confirmed ({
    callId: string,
    sessionId: string,
    uri: string,
    userNumber: string,
    sdkParams: {
        appId: string,
        channel: string,
        userId: string,
        token: string
    }
}) : void

3.2.11 failed

会话建立失败,如会话未建立前挂机等
@param sessionId         SDK区分不同会话的sessionId
@param uri               被叫号码SIP URI, 如: sip:[email protected]:5049
@param userNumber        被叫号码,如: 0123456789
@param callId            平台callId(平台会话未建立之前无callId)
@param originator        'local'/'remote'/'system' 呼叫失败方
@param cause             失败原因 Failure and End Causes 

failed ({
    sessionId: string,
    uri: string,
    userNumber: string,
    callId: string,
    originator: string,
    cause: string,
}) : void

注:
1、Failure and End Causes: https://jssip.net/documentation/3.10.x/api/causes/

3.2.12 ended

会话结束
@param sessionId         SDK区分不同会话的sessionId
@param uri               被叫号码SIP URI, 如: sip:[email protected]:5049
@param userNumber        被叫号码,如: 0123456789
@param callId            平台callId(平台会话未建立之前无callId)
@param sdkParams         媒体SDK的参数(平台会话未建立之前无sdkParams)
@param sdkParams.appId   appId
@param sdkParams.channel channelId Or roomId
@param sdkParams.userId  uid Or userId
@param sdkParams.token   token Or userSig
@param originator        'local'/'remote'/'system' 呼叫失败方
@param cause             失败原因 Failure and End Causes 

ended ({
    sessionId: string,
    uri: string,
    userNumber: string,
    callId: string,
    sdkParams: {
        appId: string,
        channel: string,
        userId: string,
        token: string
    },
    originator: string,
    cause: string
}) : void

注:
1、Failure and End Causes: https://jssip.net/documentation/3.10.x/api/causes/

3.2.13 newInfo

收到会话内消息
@param sessionId         SDK区分不同会话的sessionId
@param uri               被叫号码SIP URI, 如: sip:[email protected]:5049
@param userNumber        被叫号码,如: 0123456789
@param callId            平台callId(平台会话未建立之前无callId)
@param sdkParams         媒体SDK的参数
@param sdkParams.appId   appId
@param sdkParams.channel channelId Or roomId
@param sdkParams.userId  uid Or userId
@param sdkParams.token   token Or userSig
@param conentType        发送时指定的消息体类型
@param content           消息内容字符串


newInfo ({
    sessionId: string,
    uri: string,
    userNumber: string,
    callId: string,
    sdkParams: {
        appId: string,
        channel: string,
        userId: string,
        token: string
    }
    contentType: string,
    content: string
}) : void

3.2.14 socketError

socket连接发生错误
@param e socket连接错误

socketError (e: Error) : void

4 其他说明

SDK支持<script>标签引入和 ES6 import 引入方式,以<script>标签引入示例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>script 标签引入</title>
    <script src="./SIP_MIX_WEB.js"></script>
</head>
<body onload="onload()">

<h1>
  This is a test page for script import.
</h1>

<script>
  window.config = {
    domain: 'videocc.cincc.cn',
    path: 'webcall',
    port: 5049
  }
  function onload () {
    const sipMix = SIP_MIX_WEB.getInstance(window.config)
    console.info(sipMix)
    sipMix.start({
      password: '',
      register: false,
      debug: true
    })
  }
</script>
</body>
</html>

以import语法引入示例:

...
import SipMix from '@/libs/SIP_MIX_WEB'
...
cosnt sipMix = SipMix.getInstance({
  domain, port,
  path, debug
})
...
sipMix.on('connected', () => this.prompt = '服务器已连接。')
...
sipMix.strat({
  password,
  register
})

由于使用非NPM安装方式,在 import 引入后,可能会引起项目报错,如:

ERROR in [eslint]                                                              
...src\libs\SIP_MIX_WEB.js

  2:112     error  'define' is not defined                                                              no-undef
  2:123     error  'define' is not defined                                                              no-undef
  2:705     error  Empty block statement                                                                no-empty
  2:774     error  Empty block statement                                                                no-empty
  2:1678    error  Empty block statement                                                                no-empty
  2:8416    error  'n' is defined but never used                                                        no-unused-vars
  2:16124   error  Do not access Object.prototype method 'hasOwnProperty' from target object            no-prototype-builtins
  2:16299   error  Do not access Object.prototype method 'hasOwnProperty' from target object            no-prototype-builtins
...

可以在项目目录下修改 .eslintignore 文件,将SDK文件路径写入,如

src/libs/SIP_MIX_WEB.js