【JsSIP】JsSIP ua案例分享

本文介绍了如何使用JsSIPWebphone类通过WebSocket与UA进行连接,包括注册、连接、通话、消息发送等功能,并提供了相应的事件监听和管理。
ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

以下为UA的各种方法使用,可结合实际的使用情况来进行加工处理

import { UA, WebSocketInterface } from "jssip";

export default class JsSIPWebphone {
  constructor() {
    this.ua = "";
    this.socket = "";
    this.iceServers = "";
  }
  connect = (options) => {
    const socket = new WebSocketInterface(options.host);
    const match = options.host.match(/(?<=(ws|wss):\/\/)[^\/]+/);
    const host = match && match.length ? match[0] : "";
    // console.log(socket, match, host);
    this.socket = socket;
    socket.via_transport = "WS";
    const registerExpires = 300;
    const noAnswerTimeout = options.noAnswerTimeout || 60;
    const configuration = {
      sockets: [socket],
      uri: `${options.user}@${host}`,
      authorization_user: options.user,
      password: options.password,
      user_agent: "Webphone / 0.2.0(YSB)",
      realm: host,
      register: true,
      registrar_server: host,
      register_expires: registerExpires,
      no_answer_timeout: noAnswerTimeout,
    };
    this.ua = new UA(configuration); // 创建
    this.ua.on("connecting", (e) => {
      console.log("ua Connecting(传输连接尝试中)........");
    });
    this.ua.on("connected", (e) => {
      console.log("ua Connected(已连接)........");
    });
    this.ua.on("disconnected", (e) => {
      console.log("ua Disconnected(连接失败)........");
    });
    this.ua.on("registered", (e) => {
      console.log("ua Registered(注册成功)........");
    });
    this.ua.on("unregister", (e) => {
      console.log("ua unregister(注销UA)..........");
    });
    this.ua.on("registrationFailed", (e) => {
      console.log("ua Registration Failed(注册失败).........");
    });
    this.ua.on("registrationExpiring", (e) => {
      console.log("ua Registration Expiring(注册到期).........");
    });
    this.ua.on("newRTCSession", (e) => {
      console.log("Webphone newRTCSession.........");
      console.log(e);
    });
    this.ua.on("newMessage", (e) => {
      console.log("ua New Message(收到新消息)...........");
    });
    this.ua.on("sipEvent", (e) => {
      console.log("ua Receive Notify Request(sip事件)...........", e);
    });
    this.register();
    this.start();
  };
  register = () => {
    // 注册ua,注意:如果在UA配置参数中将register参数设置为true,UA将自动注册
    this.ua.register();
  };
  start = () => {
    // 开始连接
    this.ua.start();
  };
  stop = () => {
    // 保存当前注册状态,并断开连接
    this.ua.stop();
  };
  unregister = () => {
    // 注销UA
    this.ua.unregister({ all: true });
  };
  registrator = () => {
    // 获取 JsSIP.Registrator 注册器实例
    this.ua.registrator();
  };
  call = () => {
    // 拨打呼出多媒体电话
    const target = ""; // 目的地,URI实例
    const options = null; // 参数细节可查看文档
    this.ua.call(target, options);
  };
  sendMessage = () => {
    // 使用SIP message方法发送即时消息。
    const target = ""; //目的地,URI实例
    const body = ""; // 消息内容。表示消息正文的字符串
    const options = null; // 参数细节可查看文档
    this.ua.sendMessage(target, body, options);
  };
  terminateSessions = () => {
    // 用于呼叫终止的RTCSession。
    const options = null;
    this.ua.terminateSessions(options);
  };
  isRegistered = () => {
    // 判断是否已注册
    this.ua.isRegistered();
  };
  isConnected = () => {
    // 判断是否已连接
    this.ua.isConnected();
  };
  getParameter = () => {
    // 检索所配置的参数
    this.ua.get("realm");
  };
  setParameter = () => {
    // 修改指定的参数
    this.ua.set("reaml", "xxxxxvalue");
  };
}

本章节对ua的整体使用进行初步的案例分享,如有不妥之处或者优化建议,还请留言告知,非常感谢!!!

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值