更新记录

1.1.0(2025-08-15)

  • 修复通话录音问题

1.0.9(2025-08-13)

  • 添加startCallWithData,支持更多的参数,比如header

1.0.8(2025-08-06)

  • 修复1.0.7 android打包失败
  • 添加recording相关接口
查看更多

平台兼容性

Android Android CPU类型 iOS
适用版本区间:6.0 - 16.0 armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 适用版本区间:13 - 18

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


使用文档 (更多插件及问题,请***:zhuzheVIP1)

说明

此插件提供linphone网络电话功能

使用

const linphone = uni.requireNativePlugin("sn-linphone-sip");

在onLoad注册全局监听如下:

plus.globalEvent.addEventListener("registerChange", ({ state }) => {
  // None(0),
  // Progress(1),
  // Ok(2),
  // Cleared(3),
  // Failed(4);
  if (state == 2) {
    console.log("register ok");
    this.isRegister = true;
    uni.showToast({
      icon: "none",
      title: "注册成功",
    });
  } else {
    this.isRegister = false;
    console.log("register state:", state);
  }
});
plus.globalEvent.addEventListener("noRegister", () => {
  console.log("noRegister, 请调用注册接口");
});
plus.globalEvent.addEventListener("outgoingInit", () => {
  console.log("outgoingInit");
  uni.showToast({
    icon: "none",
    title: "初始化打电话",
  });
  this.hasOutgoing = true;
});
plus.globalEvent.addEventListener("permissionFail", () => {
  console.log("permissionFail");
});
plus.globalEvent.addEventListener("callReleased", () => {
  console.log("callReleased");
  this.hasOutgoing = false;
  uni.showToast({
    icon: "none",
    title: "电话结束",
  });
});
plus.globalEvent.addEventListener("incomingCall", (e) => {
  console.log("incomingCall", e);
});
plus.globalEvent.addEventListener("callConnected", (e) => {
  console.log("callConnected", e);
  uni.showToast({
    icon: "none",
    title: "电话接通",
  });
});
plus.globalEvent.addEventListener("callEnd", (e) => {
  console.log("callEnd", e);
});
plus.globalEvent.addEventListener("callError", (e) => {
  console.log("callError", e);
});

接口文档

  • start - 启动服务
linphone.start();
  • registerUser - 注册用户
linphone.registerUser("username", "passwd", "ip:port");
  • registerUserWithData - 注册用户
linphone.registerUserWithData({
  username: '',
  password: '',
  domain: '',
  type: 'tcp'
});
  • unregister - 注销用户
linphone.unregister();
  • startCall - 开始呼叫
// 支持全写:sip:<phone>@ip:port, 也支持仅传phone
linphone.startCall("1898888888", false);
  • startCallWithData - 开始呼叫,支持更多参数
const callData = {
  to: '1898888888',
  isVideo: false,
  displayName: '1898888888',
  // recordFile: plus.io.convertLocalFileSystemURL('_doc/test.wav'), // 需要通话录音时传
  headers: { // 可选
    a: '22',
    b: '33'
  }
}
linphone.startCallWithData(callData);
  • terminateCall - 挂断电话
linphone.terminateCall();
  • answerCall - 接听电话
linphone.answerCall();
  • declineCall - 拒接电话
linphone.declineCall();
  • enableMic - 开启麦克风
linphone.enableMic(true);
  • enableEchoCancellation - 开启回声消除
linphone.enableEchoCancellation(true);
  • toggleSpeaker - 切换扬声器
linphone.toggleSpeaker();
  • getRecordFile - 获取音频文件,仅当开启录制时有效

  • isRecording - 是否在录制中

  • startRecording - 开始录制

  • stopRecording - 停止录制

linphone.getRecordFile(file => {
  console.log('getRecordFile', file)
})

linphone.isRecording(isRe => {
  console.log('isRecording', isRe)
})
linphone.startRecording()
linphone.stopRecording()

注意事项

  • 如果发现plus.globalEvent接口无效,请用setGlobalCallback替换全局回调
linphone.setGlobalCallback(e => {
  const { event, data } = e;
  switch (event) {
    case 'registerChange':
      break;
    case 'callReleased':
      break;
    case 'callConnected':
      break;
    case 'callEnd':
      break;
    case 'incomingCall':
      break;
  }
});

另外,clearGlobalCallback可以清除设置的全局回调

隐私、权限声明

1. 本插件需要申请的系统权限列表:

android: 录音:android.permission.RECORD_AUDIO ios: 麦克风:NSMicrophoneUsageDescription

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件使用的 Linphone SDK会采集数据,详情可参考:https://www.linphone.org/privacy-policy

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率: