jessibuca-pro-talk.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. declare namespace JessibucaProTalk {
  2. enum EVENTS {
  3. talkStreamClose = 'talkStreamClose',
  4. talkStreamError = 'talkStreamError',
  5. talkStreamInactive = 'talkStreamInactive',
  6. talkGetUserMediaTimeout = 'talkGetUserMediaTimeout'
  7. }
  8. interface Config {
  9. // 语音编码类型,支持`g711a`和`g711u`,默认是`g711a`
  10. encType: string,
  11. // 语音包类型,支持`rtp`,默认是`rtp`
  12. packetType: string,
  13. // rtp包的ssrc,10位
  14. rtpSsrc: string,
  15. // 采样通道
  16. numberChannels: number,
  17. // 采样率
  18. sampleRate: number,
  19. // 采样精度
  20. sampleBitsWidth: number,
  21. // 是否开启debug模式
  22. debug: boolean,
  23. // debug模式下的日志级别,支持`debug`、`warn`,默认是`warn`
  24. debugLevel: string,
  25. // 是否开启测试麦克风,不连接ws
  26. testMicrophone: boolean,
  27. // 语音引擎,支持`worklet`和`script`,默认是`worklet`
  28. engine: string,
  29. // 是否开启检测getUserMedia超时
  30. checkGetUserMediaTimeout: boolean,
  31. // getUserMedia超时时间,单位ms
  32. getUserMediaTimeout: number
  33. }
  34. }
  35. declare class JessibucaProTalk {
  36. constructor(config?: JessibucaProTalk.Config);
  37. /**
  38. * 开启语音
  39. * @param wsUrl
  40. * @param options
  41. */
  42. startTalk(wsUrl, options: JessibucaProTalk.Config): Promise<any>;
  43. /**
  44. * 关闭语音
  45. */
  46. stopTalk(): Promise<any>;
  47. /**
  48. * 获取语音音量
  49. * * 返回值是一个0-100的数字,表示当前语音音量
  50. */
  51. getTalkVolume(): Promise<Number>;
  52. /**
  53. * 设置语音音量
  54. * @param volume 0-100的数字,表示当前语音音量
  55. */
  56. setTalkVolume(volume: number): Promise<any>;
  57. /**
  58. * 监听ws 断开
  59. * @param event
  60. * @param callback
  61. */
  62. on(event: JessibucaProTalk.EVENTS.talkStreamClose, callback: Function): void;
  63. /**
  64. * 监听 ws error
  65. * @param event
  66. * @param callback
  67. */
  68. on(event: JessibucaProTalk.EVENTS.talkStreamError, callback: Function): void;
  69. /**
  70. * 监听 stream oninactive
  71. * @param event
  72. * @param callback
  73. */
  74. on(event: JessibucaProTalk.EVENTS.talkStreamInactive, callback: Function): void;
  75. /**
  76. * 检查 getUserMedia 超时
  77. * @param event
  78. * @param callback
  79. */
  80. on(event: JessibucaProTalk.EVENTS.talkGetUserMediaTimeout, callback: Function): void;
  81. /**
  82. * 监听方法
  83. *
  84. @example
  85. JessibucaProTalk.on("talkStreamClose",function(){console.log('talkStreamClose')})
  86. */
  87. on(event: string, callback: Function): void;
  88. }
  89. export default JessibucaProTalk;