From b4b345e58ba261cf2d9b1193ce6a48f7d76d2626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Cle=CC=81ment?= Date: Wed, 16 Oct 2019 13:02:51 +0200 Subject: [PATCH 1/2] Added microphone mute functions and property --- src/components/SipProvider/index.ts | 30 +++++++++++++++++++++++++++++ src/lib/types.ts | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/src/components/SipProvider/index.ts b/src/components/SipProvider/index.ts index 6c99403..46864c3 100644 --- a/src/components/SipProvider/index.ts +++ b/src/components/SipProvider/index.ts @@ -55,6 +55,7 @@ export default class SipProvider extends React.Component< callStatus: CallStatus; callDirection: CallDirection | null; callCounterpart: string | null; + callMicrophoneIsMuted: boolean; rtcSession; } > { @@ -119,6 +120,7 @@ export default class SipProvider extends React.Component< callStatus: CALL_STATUS_IDLE, callDirection: null, callCounterpart: null, + callMicrophoneIsMuted: false, }; this.ua = null; @@ -137,6 +139,10 @@ export default class SipProvider extends React.Component< status: this.state.callStatus, direction: this.state.callDirection, counterpart: this.state.callCounterpart, + microphoneIsMuted: this.state.callMicrophoneIsMuted, + muteMicrophone: this.callMuteMicrophone, + unmuteMicrophone: this.callUnmuteMicrophone, + toggleMuteMicrophone: this.callToggleMuteMicrophone, }, registerSip: this.registerSip, unregisterSip: this.unregisterSip, @@ -436,6 +442,7 @@ export default class SipProvider extends React.Component< callStatus: CALL_STATUS_STARTING, callCounterpart: foundUri.substring(0, delimiterPosition) || foundUri, + callMicrophoneIsMuted: rtcSession.isMuted().audio, }); } else if (originator === "remote") { const foundUri = rtcRequest.from.toString(); @@ -445,6 +452,7 @@ export default class SipProvider extends React.Component< callStatus: CALL_STATUS_STARTING, callCounterpart: foundUri.substring(0, delimiterPosition) || foundUri, + callMicrophoneIsMuted: rtcSession.isMuted().audio, }); } @@ -471,6 +479,7 @@ export default class SipProvider extends React.Component< callStatus: CALL_STATUS_IDLE, callDirection: null, callCounterpart: null, + callMicrophoneIsMuted: false, }); }); @@ -484,6 +493,7 @@ export default class SipProvider extends React.Component< callStatus: CALL_STATUS_IDLE, callDirection: null, callCounterpart: null, + callMicrophoneIsMuted: false, }); }); @@ -546,4 +556,24 @@ export default class SipProvider extends React.Component< public render() { return this.props.children; } + + private callMuteMicrophone = () => { + if (this.state.rtcSession && !this.state.callMicrophoneIsMuted) { + this.state.rtcSession.mute({ audio: true, video: false }); + this.setState({ callMicrophoneIsMuted: true }); + } + }; + + private callUnmuteMicrophone = () => { + if (this.state.rtcSession && this.state.callMicrophoneIsMuted) { + this.state.rtcSession.unmute({ audio: true, video: false }); + this.setState({ callMicrophoneIsMuted: false }); + } + }; + + private callToggleMuteMicrophone = () => { + return this.state.callMicrophoneIsMuted + ? this.callUnmuteMicrophone() + : this.callMuteMicrophone(); + }; } diff --git a/src/lib/types.ts b/src/lib/types.ts index 1265303..0a866c9 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -62,4 +62,8 @@ export const callPropType = PropTypes.shape({ status: PropTypes.string, direction: PropTypes.string, counterpart: PropTypes.string, + microphoneIsMuted: PropTypes.bool, + muteMicrophone: PropTypes.func, + unmuteMicrophone: PropTypes.func, + toggleMuteMicrophone: PropTypes.func, }); From 8aadd44b4692c79857156175281454b8f5bacdf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Cle=CC=81ment?= Date: Wed, 16 Oct 2019 13:18:03 +0200 Subject: [PATCH 2/2] Added information about new microphone muting methods/properties to README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9e95237..71df605 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,9 @@ To make calls, simply use these functions: The value for `destination` argument equals to the target SIP user without the host part (e.g. `+441234567890` or `bob`). The omitted host part is equal to host you’ve defined in `SipProvider` props (e.g. `sip.example.com`). +You may also mute your microphone during calls with the `call.toggleMuteMicrophone()`, `call.muteMicrophone` and `call.unmuteMicrophone` methods. +You can check whether the microphone is used with the `call.microphoneIsMuted` property. + --- The values for `sip.status`, `sip.errorType`, `call.status` and `call.direction` can be imported as constants to make typos easier to detect: