-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Myriad of changes #9
Draft
danjenkins
wants to merge
5
commits into
drachtio:main
Choose a base branch
from
nimbleape:myriad-of-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c28ec74
Allow SimRinger class users access to events
danjenkins 226ce45
allow external application to cancel simringer
danjenkins 7653af2
whitespace changes to follow the rest of the file
danjenkins 2d7fac2
dnt clear whole map, delete each uri
danjenkins bf29abd
add super() for Emitter extends
danjenkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ A common need is to do a simultaneous ring of multiple SIP endpoints in response | |
|
||
This function provides a forking outdial B2BUA that connects the caller to the first endpoint that answers. | ||
|
||
##### basic usage | ||
##### Basic usage | ||
In basic usage, the exported `simring` function acts almost exactly like [Srf#createB2BUA](https://drachtio.org/api#srf-create-b2bua), except that you pass an array of sip URIs rather than a single sip URI. | ||
```js | ||
const {simring} = require('drachtio-fn-b2b-sugar'); | ||
|
@@ -23,7 +23,7 @@ srf.invite(async (req, res) { | |
``` | ||
All of the options that you can pass to [Srf#createB2BUA](https://drachtio.org/api#srf-create-b2bua) can be passed to `simring`. | ||
|
||
##### with logging | ||
##### With logging | ||
If you want logging from simring, you can treat the exported `simring` reference as a factory function that you invoke with a single argument, that being the logger object that you want to be used. That object must provide 'debug', 'info', and 'error' functions (e.g. [pino](https://www.npmjs.com/package/pino)). | ||
|
||
Invoking the factory function then returns another function that does the actual simring. | ||
|
@@ -40,8 +40,28 @@ srf.invite(async (req, res) { | |
} | ||
}); | ||
``` | ||
|
||
##### Timouts values & Global vs individual leg timeouts | ||
|
||
By default the timeout you can pass to `simring` is assigned to each outbound leg in the fork. The default value is `20` seconds. You may want to change this so that it's a global timeout rather than individual timeouts. You can pass in `globalTimeout` within the `opts` object. You can also change the timeout value by setting `timeout` in that object too; it's set in seconds. | ||
|
||
```js | ||
const {simring} = require('drachtio-fn-b2b-sugar'); | ||
srf.invite(async (req, res) { | ||
try { | ||
const {uas, uac} = await simring(req, res, ['sip:[email protected]', 'sip:[email protected]'], { | ||
globalTimeout: true, | ||
timeout: 30 | ||
}); | ||
console.info(`successfully connected to ${uas.remote.uri}`); | ||
} catch (err) { | ||
console.log(err, 'Error connecting call'); | ||
} | ||
}); | ||
``` | ||
|
||
## Simring class | ||
A more advanced usage is to to start a simring against a list of endpoints, and then later (before any have answered) add one or more new endpoints to the simring list. | ||
A more advanced usage is to to start a simring against a list of endpoints, and then later (before any have answered) add one or more new endpoints to the simring list. | ||
|
||
This would be useful, for instance, in a scenario where you are ringing all of the registered devices for a user and while doing that a new device registers that you also want to include. | ||
|
||
|
@@ -57,13 +77,30 @@ srf.invite(async (req, res) { | |
console.info(`successfully connected to ${uas.remote.uri}`); | ||
}) | ||
.catch((err) => console.log(err, 'Error connecting call')); | ||
|
||
// assume we are alerted when a new device registers | ||
someEmitter.on('someRegisterEvent', () => { | ||
if (!simring.finished) simring.addUri('sip:[email protected]'); | ||
}); | ||
``` | ||
|
||
##### Events | ||
|
||
The Simring class emits two different events - `finalSuccess` and `failure` | ||
|
||
###### finalSuccess | ||
|
||
Emits the uri that was eventually successful. - `uri` | ||
|
||
###### failure | ||
|
||
Emits an object containing the error and the uri that failed - `{err, uri}` | ||
|
||
##### Diasble the timeout and Promise rejection | ||
|
||
You may want to disable simringer's ability to handle a timeout completely as well as decide when your simringer is indeed finished. | ||
This might be the case if you have an active simringer but you want to add a URI later on. Without the ability to handle this decison yourself lets say you add a URI straight away and it fails (500 response), the simringer will see that as a failed simringer and reject the returned promise. But you're still within your timeout value within your app and you want to add another URI to the now failed simringer. The way to handle this is to take control of the timeout yourself by passing in a timeout value of `null` or `false`. In this case, you now need to cancel the Simring class yourself using the exported `Simring#cancel` method. | ||
|
||
## transfer (REFER handler) | ||
|
||
Handle REFER messasges in your B2B dialogs. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't you need to call
super()
as the first thing in the constructor?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're probably 100% right here :) Like I said - completely non tested. I'll go test the changes myself this week and we can go from there