zann-voice 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -8
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +14 -3
package/README.md
CHANGED
|
@@ -38,11 +38,11 @@ voice.destroy();
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
//关闭麦克风
|
|
41
|
-
voice.
|
|
41
|
+
voice.stopMicrophone();
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
//打开被关闭的麦克风 必须在click事件中调用
|
|
45
|
-
voice.
|
|
45
|
+
voice.startMicrophone();
|
|
46
46
|
|
|
47
47
|
```
|
|
48
48
|
|
|
@@ -74,7 +74,9 @@ voice.connect({
|
|
|
74
74
|
| onTrack | function |是 | 监听媒体流[请参考](https://developer.mozilla.org/en-US/docs/Web/API/RTCTrackEvent#example) |
|
|
75
75
|
| onError | function |是 | 监听错误问题 |
|
|
76
76
|
| onMessage | function |是 | 监听websocket 发来的内容 |
|
|
77
|
-
| onAuth | function | 是 |
|
|
77
|
+
| onAuth | function | 是 | 监听到需要用户授权麦克风或者摄像头,返回值参考 <code>MediaStream 授权状态</code>|
|
|
78
|
+
| onMicrophoneChange | function | 否 | 监听麦克风变化,并返回 MediaStream |
|
|
79
|
+
| onCameraChange | function | 否 | 监听摄像头变化,并返回 MediaStream |
|
|
78
80
|
|
|
79
81
|
媒体模式参数
|
|
80
82
|
``` markdown
|
|
@@ -87,18 +89,35 @@ voice.connect({
|
|
|
87
89
|
> 销毁,或者挂断由connect()创建的通话
|
|
88
90
|
> <br/>必须先调用connect 才可正常调用此方法
|
|
89
91
|
|
|
90
|
-
### **3.
|
|
91
|
-
> 如果调用了
|
|
92
|
+
### **3.async startMicrophone()开启麦克风**
|
|
93
|
+
> 如果调用了stopMicrophone 关闭麦克风,可以调用此方法恢复麦克风,需要click事件
|
|
92
94
|
> <br/>必须先调用connect 才可正常调用此方法
|
|
93
95
|
|
|
94
|
-
### **4.
|
|
96
|
+
### **4.stopMicrophone()关闭麦克风**
|
|
95
97
|
> 临时关闭麦克风,但不会打断通话
|
|
96
98
|
> <br/>必须先调用connect 才可正常调用此方法
|
|
97
99
|
|
|
98
|
-
### **5.startCamera()开启摄像头**
|
|
100
|
+
### **5.async startCamera()开启摄像头**
|
|
99
101
|
> 如果调用了stopCamera 关闭摄像头,可以调用此方法恢复摄像头,需要click事件
|
|
100
102
|
> <br/>必须先调用connect 才可正常调用此方法
|
|
101
103
|
|
|
102
104
|
### **6.stopCamera()关闭摄像头**
|
|
103
105
|
> 临时关闭摄像头,但不会打断通话
|
|
104
|
-
> <br/>必须先调用connect 才可正常调用此方法
|
|
106
|
+
> <br/>必须先调用connect 才可正常调用此方法
|
|
107
|
+
|
|
108
|
+
### **7.async authorize()获取授权状态**
|
|
109
|
+
|
|
110
|
+
**1.返回值**
|
|
111
|
+
| 属性 | 类型| 是否必须 |备注 |
|
|
112
|
+
| -------------| :-----------: | :-----------: | :-----------: |
|
|
113
|
+
| microphone | string |是 | 麦克风授权状态 |
|
|
114
|
+
| camera | string |是 | 摄像头授权状态 |
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
**2.<code>MediaStream 授权状态</code>**
|
|
118
|
+
| 属性 | 类型 |备注 |
|
|
119
|
+
| ------------- | :-----------: | :-----------: |
|
|
120
|
+
| granted | string | 用户已经授权 |
|
|
121
|
+
| denied | string | 用户明确拒绝 |
|
|
122
|
+
| prompt | string | 尚未询问 |
|
|
123
|
+
| unknown | string | 无法获取状态 |
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(o,e,s,i){if(s==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?o!==e||!i:!e.has(o))throw new TypeError("Cannot read private member from an object whose class did not declare it");return s==="m"?i:s==="a"?i.call(o):i?i.value:e.get(o)}function n(o,e,s,i,
|
|
1
|
+
"use strict";function t(o,e,s,i){if(s==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?o!==e||!i:!e.has(o))throw new TypeError("Cannot read private member from an object whose class did not declare it");return s==="m"?i:s==="a"?i.call(o):i?i.value:e.get(o)}function n(o,e,s,i,f){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!f)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?o!==e||!f:!e.has(o))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?f.call(o,s):f?f.value=s:e.set(o,s),s}typeof SuppressedError=="function"&&SuppressedError;var h,a,r,c,m,_,w,p,g,W,V,M,k,T,S,l,d,C,v,y,E,b;class N{constructor({wss:e,TURN:s,maxReconnect:i=5}){h.add(this),a.set(this,null),r.set(this,null),c.set(this,null),m.set(this,!1),_.set(this,!1),w.set(this,0),p.set(this,5),g.set(this,""),W.set(this,{urls:""}),V.set(this,void 0),M.set(this,void 0),k.set(this,void 0),T.set(this,void 0),S.set(this,void 0),l.set(this,void 0),d.set(this,void 0),n(this,g,e,"f"),n(this,W,s,"f"),n(this,p,i,"f")}async connect({media:e={audio:!0,video:!1},onOpen:s,onTrack:i,onError:f,onMessage:Z,onAuth:O,onMicrophoneChange:R,onCameraChange:P}){if(t(this,m,"f")){console.warn("\u26A0\uFE0F \u5DF2\u7ECF\u5B58\u5728 RTC/WS\uFF0C\u4E0D\u91CD\u590D\u521B\u5EFA");return}n(this,_,!1,"f"),n(this,w,0,"f"),n(this,V,s,"f"),n(this,M,i,"f"),n(this,k,f,"f"),n(this,T,Z,"f"),n(this,S,O,"f"),n(this,l,R,"f"),n(this,d,P,"f"),console.log("\u2728 Creating WebRTC + WebSocket..."),n(this,a,new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun1.l.google.com:19302"},t(this,W,"f")]}),"f"),t(this,a,"f").onicecandidate=u=>{u.candidate&&t(this,r,"f")?.readyState===WebSocket.OPEN&&t(this,r,"f").send(JSON.stringify({type:"ice",data:u.candidate}))},t(this,a,"f").ontrack=u=>t(this,M,"f").call(this,u),t(this,a,"f").onconnectionstatechange=()=>{const u=t(this,a,"f")?.connectionState;console.log("RTC connection state:",u),!t(this,_,"f")&&(u==="disconnected"||u==="failed")&&(console.warn("RTC disconnected, retrying offer..."),t(this,h,"m",y).call(this))},t(this,h,"m",C).call(this),n(this,m,!0,"f"),e.audio&&await this.startMicrophone(),e.video&&await this.startCamera()}async startMicrophone(){if(!t(this,a,"f")){console.warn("\u274C startMic \u9700\u8981\u5148\u8C03\u7528 create()");return}if(!t(this,c,"f")?.getAudioTracks().length)try{const e=await navigator.mediaDevices.getUserMedia({audio:!0});e.getAudioTracks().forEach(s=>t(this,a,"f").addTrack(s,e)),t(this,c,"f")||n(this,c,new MediaStream,"f"),e.getAudioTracks().forEach(s=>t(this,c,"f").addTrack(s)),t(this,h,"m",y).call(this),t(this,l,"f")&&t(this,l,"f").call(this,!0,e)}catch(e){t(this,S,"f").call(this,e),t(this,l,"f")&&t(this,l,"f").call(this,!1,null)}}stopMicrophone(){t(this,c,"f")&&(t(this,c,"f").getAudioTracks().forEach(e=>{e.stop();const s=t(this,a,"f")?.getSenders().find(i=>i.track===e);s&&t(this,a,"f")?.removeTrack(s)}),t(this,l,"f")&&t(this,l,"f").call(this,!1,null))}async startCamera(){if(!t(this,a,"f")){console.warn("\u274C startCamera \u9700\u8981\u5148\u8C03\u7528 create()");return}if(!t(this,c,"f")?.getVideoTracks().length)try{const e=await navigator.mediaDevices.getUserMedia({video:!0});e.getVideoTracks().forEach(s=>t(this,a,"f").addTrack(s,e)),t(this,c,"f")||n(this,c,new MediaStream,"f"),e.getVideoTracks().forEach(s=>t(this,c,"f").addTrack(s)),t(this,h,"m",y).call(this),t(this,d,"f")&&t(this,d,"f").call(this,!0,e)}catch(e){t(this,S,"f").call(this,e),t(this,d,"f")&&t(this,d,"f").call(this,!1,null)}}stopCamera(){t(this,c,"f")&&(t(this,c,"f").getVideoTracks().forEach(e=>{e.stop();const s=t(this,a,"f")?.getSenders().find(i=>i.track===e);s&&t(this,a,"f")?.removeTrack(s)}),t(this,d,"f")&&t(this,d,"f").call(this,!1,null))}destroy(){console.log("\u{1F6D1} Destroying ZannVoice..."),n(this,_,!0,"f"),this.stopMicrophone(),this.stopCamera(),t(this,h,"m",E).call(this),t(this,h,"m",b).call(this),n(this,m,!1,"f")}async authorize(){if(!navigator.permissions)return{microphone:"unknown",camera:"unknown"};const e=async f=>{try{return(await navigator.permissions.query({name:f})).state}catch{return"unknown"}},s=await e("microphone"),i=await e("camera");return{microphone:s,camera:i}}}a=new WeakMap,r=new WeakMap,c=new WeakMap,m=new WeakMap,_=new WeakMap,w=new WeakMap,p=new WeakMap,g=new WeakMap,W=new WeakMap,V=new WeakMap,M=new WeakMap,k=new WeakMap,T=new WeakMap,S=new WeakMap,l=new WeakMap,d=new WeakMap,h=new WeakSet,C=function o(e=1e3){t(this,g,"f")&&(n(this,r,new WebSocket(t(this,g,"f")),"f"),t(this,r,"f").onopen=()=>{console.log("\u2705 WS connected"),n(this,w,0,"f"),t(this,a,"f")?.connectionState!=="connected"&&t(this,h,"m",y).call(this)},t(this,r,"f").onmessage=s=>t(this,h,"m",v).call(this,s),t(this,r,"f").onerror=s=>t(this,k,"f").call(this,s),t(this,r,"f").onclose=()=>{var s;if(!t(this,_,"f")){if(t(this,w,"f")>=t(this,p,"f")){console.error(`\u274C WS \u8D85\u8FC7\u6700\u5927\u91CD\u8FDE\u6B21\u6570 ${t(this,p,"f")}`),t(this,k,"f")?.call(this,new Error(`WS exceeded max reconnects ${t(this,p,"f")}`));return}n(this,w,(s=t(this,w,"f"),s++,s),"f"),console.warn(`\u{1F504} WS disconnected, retrying in ${e}ms... [${t(this,w,"f")}/${t(this,p,"f")}]`),setTimeout(()=>t(this,h,"m",o).call(this,Math.min(e*2,1e4)),e)}})},v=async function(e){const s=JSON.parse(e.data);switch(s.type){case"answer":await t(this,a,"f")?.setRemoteDescription(s.data),t(this,V,"f").call(this);break;case"ice":await t(this,a,"f")?.addIceCandidate(s.data);break;case"offer":await t(this,a,"f")?.setRemoteDescription(s.data);const i=await t(this,a,"f")?.createAnswer();i&&(await t(this,a,"f")?.setLocalDescription(i),t(this,r,"f")?.send(JSON.stringify({type:"answer",data:i})));break;default:t(this,T,"f").call(this,e);break}},y=async function(){if(!t(this,a,"f")||!t(this,r,"f")||t(this,r,"f").readyState!==WebSocket.OPEN)return;const e=await t(this,a,"f").createOffer();await t(this,a,"f").setLocalDescription(e),t(this,r,"f").send(JSON.stringify({type:"offer",data:e}))},E=function(){t(this,a,"f")?.getSenders().forEach(e=>e.track?.stop()),t(this,a,"f")?.close(),n(this,a,null,"f")},b=function(){t(this,r,"f")&&t(this,r,"f").readyState===WebSocket.OPEN&&t(this,r,"f").close(),n(this,r,null,"f")},module.exports=N;
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(o,e,s,i){if(s==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?o!==e||!i:!e.has(o))throw new TypeError("Cannot read private member from an object whose class did not declare it");return s==="m"?i:s==="a"?i.call(o):i?i.value:e.get(o)}function n(o,e,s,i,
|
|
1
|
+
function t(o,e,s,i){if(s==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?o!==e||!i:!e.has(o))throw new TypeError("Cannot read private member from an object whose class did not declare it");return s==="m"?i:s==="a"?i.call(o):i?i.value:e.get(o)}function n(o,e,s,i,f){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!f)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?o!==e||!f:!e.has(o))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?f.call(o,s):f?f.value=s:e.set(o,s),s}typeof SuppressedError=="function"&&SuppressedError;var h,a,r,c,m,_,w,p,g,W,V,M,k,T,S,l,d,C,v,y,E,b;class N{constructor({wss:e,TURN:s,maxReconnect:i=5}){h.add(this),a.set(this,null),r.set(this,null),c.set(this,null),m.set(this,!1),_.set(this,!1),w.set(this,0),p.set(this,5),g.set(this,""),W.set(this,{urls:""}),V.set(this,void 0),M.set(this,void 0),k.set(this,void 0),T.set(this,void 0),S.set(this,void 0),l.set(this,void 0),d.set(this,void 0),n(this,g,e,"f"),n(this,W,s,"f"),n(this,p,i,"f")}async connect({media:e={audio:!0,video:!1},onOpen:s,onTrack:i,onError:f,onMessage:Z,onAuth:O,onMicrophoneChange:R,onCameraChange:P}){if(t(this,m,"f")){console.warn("\u26A0\uFE0F \u5DF2\u7ECF\u5B58\u5728 RTC/WS\uFF0C\u4E0D\u91CD\u590D\u521B\u5EFA");return}n(this,_,!1,"f"),n(this,w,0,"f"),n(this,V,s,"f"),n(this,M,i,"f"),n(this,k,f,"f"),n(this,T,Z,"f"),n(this,S,O,"f"),n(this,l,R,"f"),n(this,d,P,"f"),console.log("\u2728 Creating WebRTC + WebSocket..."),n(this,a,new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun1.l.google.com:19302"},t(this,W,"f")]}),"f"),t(this,a,"f").onicecandidate=u=>{u.candidate&&t(this,r,"f")?.readyState===WebSocket.OPEN&&t(this,r,"f").send(JSON.stringify({type:"ice",data:u.candidate}))},t(this,a,"f").ontrack=u=>t(this,M,"f").call(this,u),t(this,a,"f").onconnectionstatechange=()=>{const u=t(this,a,"f")?.connectionState;console.log("RTC connection state:",u),!t(this,_,"f")&&(u==="disconnected"||u==="failed")&&(console.warn("RTC disconnected, retrying offer..."),t(this,h,"m",y).call(this))},t(this,h,"m",C).call(this),n(this,m,!0,"f"),e.audio&&await this.startMicrophone(),e.video&&await this.startCamera()}async startMicrophone(){if(!t(this,a,"f")){console.warn("\u274C startMic \u9700\u8981\u5148\u8C03\u7528 create()");return}if(!t(this,c,"f")?.getAudioTracks().length)try{const e=await navigator.mediaDevices.getUserMedia({audio:!0});e.getAudioTracks().forEach(s=>t(this,a,"f").addTrack(s,e)),t(this,c,"f")||n(this,c,new MediaStream,"f"),e.getAudioTracks().forEach(s=>t(this,c,"f").addTrack(s)),t(this,h,"m",y).call(this),t(this,l,"f")&&t(this,l,"f").call(this,!0,e)}catch(e){t(this,S,"f").call(this,e),t(this,l,"f")&&t(this,l,"f").call(this,!1,null)}}stopMicrophone(){t(this,c,"f")&&(t(this,c,"f").getAudioTracks().forEach(e=>{e.stop();const s=t(this,a,"f")?.getSenders().find(i=>i.track===e);s&&t(this,a,"f")?.removeTrack(s)}),t(this,l,"f")&&t(this,l,"f").call(this,!1,null))}async startCamera(){if(!t(this,a,"f")){console.warn("\u274C startCamera \u9700\u8981\u5148\u8C03\u7528 create()");return}if(!t(this,c,"f")?.getVideoTracks().length)try{const e=await navigator.mediaDevices.getUserMedia({video:!0});e.getVideoTracks().forEach(s=>t(this,a,"f").addTrack(s,e)),t(this,c,"f")||n(this,c,new MediaStream,"f"),e.getVideoTracks().forEach(s=>t(this,c,"f").addTrack(s)),t(this,h,"m",y).call(this),t(this,d,"f")&&t(this,d,"f").call(this,!0,e)}catch(e){t(this,S,"f").call(this,e),t(this,d,"f")&&t(this,d,"f").call(this,!1,null)}}stopCamera(){t(this,c,"f")&&(t(this,c,"f").getVideoTracks().forEach(e=>{e.stop();const s=t(this,a,"f")?.getSenders().find(i=>i.track===e);s&&t(this,a,"f")?.removeTrack(s)}),t(this,d,"f")&&t(this,d,"f").call(this,!1,null))}destroy(){console.log("\u{1F6D1} Destroying ZannVoice..."),n(this,_,!0,"f"),this.stopMicrophone(),this.stopCamera(),t(this,h,"m",E).call(this),t(this,h,"m",b).call(this),n(this,m,!1,"f")}async authorize(){if(!navigator.permissions)return{microphone:"unknown",camera:"unknown"};const e=async f=>{try{return(await navigator.permissions.query({name:f})).state}catch{return"unknown"}},s=await e("microphone"),i=await e("camera");return{microphone:s,camera:i}}}a=new WeakMap,r=new WeakMap,c=new WeakMap,m=new WeakMap,_=new WeakMap,w=new WeakMap,p=new WeakMap,g=new WeakMap,W=new WeakMap,V=new WeakMap,M=new WeakMap,k=new WeakMap,T=new WeakMap,S=new WeakMap,l=new WeakMap,d=new WeakMap,h=new WeakSet,C=function o(e=1e3){t(this,g,"f")&&(n(this,r,new WebSocket(t(this,g,"f")),"f"),t(this,r,"f").onopen=()=>{console.log("\u2705 WS connected"),n(this,w,0,"f"),t(this,a,"f")?.connectionState!=="connected"&&t(this,h,"m",y).call(this)},t(this,r,"f").onmessage=s=>t(this,h,"m",v).call(this,s),t(this,r,"f").onerror=s=>t(this,k,"f").call(this,s),t(this,r,"f").onclose=()=>{var s;if(!t(this,_,"f")){if(t(this,w,"f")>=t(this,p,"f")){console.error(`\u274C WS \u8D85\u8FC7\u6700\u5927\u91CD\u8FDE\u6B21\u6570 ${t(this,p,"f")}`),t(this,k,"f")?.call(this,new Error(`WS exceeded max reconnects ${t(this,p,"f")}`));return}n(this,w,(s=t(this,w,"f"),s++,s),"f"),console.warn(`\u{1F504} WS disconnected, retrying in ${e}ms... [${t(this,w,"f")}/${t(this,p,"f")}]`),setTimeout(()=>t(this,h,"m",o).call(this,Math.min(e*2,1e4)),e)}})},v=async function(e){const s=JSON.parse(e.data);switch(s.type){case"answer":await t(this,a,"f")?.setRemoteDescription(s.data),t(this,V,"f").call(this);break;case"ice":await t(this,a,"f")?.addIceCandidate(s.data);break;case"offer":await t(this,a,"f")?.setRemoteDescription(s.data);const i=await t(this,a,"f")?.createAnswer();i&&(await t(this,a,"f")?.setLocalDescription(i),t(this,r,"f")?.send(JSON.stringify({type:"answer",data:i})));break;default:t(this,T,"f").call(this,e);break}},y=async function(){if(!t(this,a,"f")||!t(this,r,"f")||t(this,r,"f").readyState!==WebSocket.OPEN)return;const e=await t(this,a,"f").createOffer();await t(this,a,"f").setLocalDescription(e),t(this,r,"f").send(JSON.stringify({type:"offer",data:e}))},E=function(){t(this,a,"f")?.getSenders().forEach(e=>e.track?.stop()),t(this,a,"f")?.close(),n(this,a,null,"f")},b=function(){t(this,r,"f")&&t(this,r,"f").readyState===WebSocket.OPEN&&t(this,r,"f").close(),n(this,r,null,"f")};export{N as default};
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ type voice = {
|
|
|
8
8
|
onError: (event: any) => void;
|
|
9
9
|
onMessage: (event: any) => void;
|
|
10
10
|
onAuth: (event: any) => void;
|
|
11
|
+
onMicrophoneChange?: (state: boolean, event: MediaStream | null) => void;
|
|
12
|
+
onCameraChange?: (state: boolean, event: MediaStream | null) => void;
|
|
11
13
|
};
|
|
12
14
|
declare class ZannVoice {
|
|
13
15
|
#private;
|
|
@@ -33,19 +35,21 @@ declare class ZannVoice {
|
|
|
33
35
|
* @param onError 创建出现了问题
|
|
34
36
|
* @param onMessage 监听websocket 发来的内容
|
|
35
37
|
* @param onAuth 当需要授权时候发生
|
|
38
|
+
* @param onMicrophoneChange 监听麦克风变化 state 是否开启麦克风
|
|
39
|
+
* @param onCameraChange 监听摄像头变化 state 是否开启麦克风
|
|
36
40
|
* @returns
|
|
37
41
|
*/
|
|
38
|
-
connect({ media, onOpen, onTrack, onError, onMessage, onAuth, }: voice): Promise<void>;
|
|
42
|
+
connect({ media, onOpen, onTrack, onError, onMessage, onAuth, onMicrophoneChange, onCameraChange }: voice): Promise<void>;
|
|
39
43
|
/**
|
|
40
44
|
* 开启麦克风
|
|
41
45
|
* @returns
|
|
42
46
|
*/
|
|
43
|
-
|
|
47
|
+
startMicrophone(): Promise<void>;
|
|
44
48
|
/**
|
|
45
49
|
* 关闭麦克风
|
|
46
50
|
* @returns
|
|
47
51
|
*/
|
|
48
|
-
|
|
52
|
+
stopMicrophone(): void;
|
|
49
53
|
/**
|
|
50
54
|
* 开启摄像头
|
|
51
55
|
* @returns
|
|
@@ -60,5 +64,12 @@ declare class ZannVoice {
|
|
|
60
64
|
* 注销,挂断
|
|
61
65
|
*/
|
|
62
66
|
destroy(): void;
|
|
67
|
+
/**
|
|
68
|
+
* 获取授权状态
|
|
69
|
+
*/
|
|
70
|
+
authorize(): Promise<{
|
|
71
|
+
microphone: string;
|
|
72
|
+
camera: string;
|
|
73
|
+
}>;
|
|
63
74
|
}
|
|
64
75
|
export default ZannVoice;
|