From f62fc8db4bab2676b007eb0193dec7880453f2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Cle=CC=81ment?= Date: Wed, 16 Oct 2019 11:26:57 +0200 Subject: [PATCH 1/5] Added hold/unhold/isOnHold functions to Call --- src/components/SipProvider/index.ts | 36 ++++++++++++++++++++++++++++- src/lib/types.ts | 4 ++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/components/SipProvider/index.ts b/src/components/SipProvider/index.ts index 6c99403..a3ba9cc 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; + callIsOnHold: boolean; rtcSession; } > { @@ -96,7 +97,7 @@ export default class SipProvider extends React.Component< autoAnswer: false, iceRestart: false, sessionTimersExpires: 120, - extraHeaders: { register: [], invite: [] }, + extraHeaders: { register: [], invite: [], hold: [] }, iceServers: [], debug: false, @@ -119,6 +120,7 @@ export default class SipProvider extends React.Component< callStatus: CALL_STATUS_IDLE, callDirection: null, callCounterpart: null, + callIsOnHold: false, }; this.ua = null; @@ -137,6 +139,9 @@ export default class SipProvider extends React.Component< status: this.state.callStatus, direction: this.state.callDirection, counterpart: this.state.callCounterpart, + isOnHold: this.state.callIsOnHold, + hold: this.callHold, + unhold: this.callUnhold, }, registerSip: this.registerSip, unregisterSip: this.unregisterSip, @@ -436,6 +441,7 @@ export default class SipProvider extends React.Component< callStatus: CALL_STATUS_STARTING, callCounterpart: foundUri.substring(0, delimiterPosition) || foundUri, + callIsOnHold: rtcSession.isOnHold().local, }); } else if (originator === "remote") { const foundUri = rtcRequest.from.toString(); @@ -546,4 +552,32 @@ export default class SipProvider extends React.Component< public render() { return this.props.children; } + + private callHold = (useUpdate = false) => { + const holdStatus = this.state.rtcSession.isOnHold(); + if (!holdStatus.local) { + const options = { + useUpdate, + extraHeaders: this.props.extraHeaders.hold, + }; + const done = () => { + this.setState({ callIsOnHold: true }); + }; + this.state.rtcSession.hold(options, done); + } + }; + + private callUnhold = (useUpdate = false) => { + const holdStatus = this.state.rtcSession.isOnHold(); + if (holdStatus.local) { + const options = { + useUpdate, + extraHeaders: this.props.extraHeaders.hold, + }; + const done = () => { + this.setState({ callIsOnHold: false }); + }; + this.state.rtcSession.unhold(options, done); + } + }; } diff --git a/src/lib/types.ts b/src/lib/types.ts index 1265303..bbea22f 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -3,6 +3,7 @@ import * as PropTypes from "prop-types"; export interface ExtraHeaders { register?: string[]; invite?: string[]; + hold?: string[]; } export const extraHeadersPropType = PropTypes.objectOf( PropTypes.arrayOf(PropTypes.string), @@ -62,4 +63,7 @@ export const callPropType = PropTypes.shape({ status: PropTypes.string, direction: PropTypes.string, counterpart: PropTypes.string, + hold: PropTypes.func, + unhold: PropTypes.func, + isOnHold: PropTypes.bool, }); From 624fa0ccb92973c2afbf98ff02045b0639dc34a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Cle=CC=81ment?= Date: Wed, 16 Oct 2019 11:29:59 +0200 Subject: [PATCH 2/5] Updated README with new functions and properties --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9e95237..d45a421 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,8 @@ 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`). +During a call you can put it on hold using the `call.hold()` and `call.unhold()` functions. You can also get hold status with the `call.isOnHold` property. + --- The values for `sip.status`, `sip.errorType`, `call.status` and `call.direction` can be imported as constants to make typos easier to detect: From 4aed6585ec7764fb2806196e242cab88892a96b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Cle=CC=81ment?= Date: Wed, 16 Oct 2019 12:41:11 +0200 Subject: [PATCH 3/5] Added callIsOnHold when originator is "remote" --- src/components/SipProvider/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/SipProvider/index.ts b/src/components/SipProvider/index.ts index a3ba9cc..1288bd3 100644 --- a/src/components/SipProvider/index.ts +++ b/src/components/SipProvider/index.ts @@ -451,6 +451,7 @@ export default class SipProvider extends React.Component< callStatus: CALL_STATUS_STARTING, callCounterpart: foundUri.substring(0, delimiterPosition) || foundUri, + callIsOnHold: rtcSession.isOnHold().local, }); } From 606de230eee4b5c490c486a3f2c7cb05d2974194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Cle=CC=81ment?= Date: Wed, 16 Oct 2019 13:05:06 +0200 Subject: [PATCH 4/5] Added call hold toggle function --- src/components/SipProvider/index.ts | 8 ++++++++ src/lib/types.ts | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/SipProvider/index.ts b/src/components/SipProvider/index.ts index 1288bd3..ce0a771 100644 --- a/src/components/SipProvider/index.ts +++ b/src/components/SipProvider/index.ts @@ -142,6 +142,7 @@ export default class SipProvider extends React.Component< isOnHold: this.state.callIsOnHold, hold: this.callHold, unhold: this.callUnhold, + toggleHold: this.callToggleHold, }, registerSip: this.registerSip, unregisterSip: this.unregisterSip, @@ -581,4 +582,11 @@ export default class SipProvider extends React.Component< this.state.rtcSession.unhold(options, done); } }; + + private callToggleHold = (useUpdate = false) => { + const holdStatus = this.state.rtcSession.isOnHold(); + return holdStatus.local + ? this.callUnhold(useUpdate) + : this.callHold(useUpdate); + }; } diff --git a/src/lib/types.ts b/src/lib/types.ts index bbea22f..877c463 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -63,7 +63,8 @@ export const callPropType = PropTypes.shape({ status: PropTypes.string, direction: PropTypes.string, counterpart: PropTypes.string, + isOnHold: PropTypes.bool, hold: PropTypes.func, unhold: PropTypes.func, - isOnHold: PropTypes.bool, + toggleHold: PropTypes.func, }); From 9fe636bfa5f204797241bc62ab68d962c9214161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Cle=CC=81ment?= Date: Wed, 16 Oct 2019 13:11:55 +0200 Subject: [PATCH 5/5] Added callIsOnHold reset on ended call --- src/components/SipProvider/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/SipProvider/index.ts b/src/components/SipProvider/index.ts index ce0a771..0b5f01a 100644 --- a/src/components/SipProvider/index.ts +++ b/src/components/SipProvider/index.ts @@ -492,6 +492,7 @@ export default class SipProvider extends React.Component< callStatus: CALL_STATUS_IDLE, callDirection: null, callCounterpart: null, + callIsOnHold: false, }); });