-
Notifications
You must be signed in to change notification settings - Fork 789
Subscribe support #711
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
base: master
Are you sure you want to change the base?
Subscribe support #711
Conversation
|
Hi @ikq, JsSIP code must have the same style in order to make it readable and maintainable. Comments before making a deeper review:
Please take a certain file (ie: RTCSession.js) as a reference and try to stick to its style. |
|
Thanks for the cleanup, 👍 We'll review the PR as we can. |
|
@ikq, Cosmetic comment, we use camelCase in API method arguments (not in 100% of the cases, I know, but we will get there). Could you please make such change? |
jmillan
left a comment
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.
I've made the first review.
Please go through all the comments and modify as needed. We'll go for sencond review afterwards.
|
I mostly fixed the issues. [I thought about dialog: About dialog, seems: dialog interface:
other functionality:
It's already implemented in Subscriber/Notifier. |
|
Hi, Super busy lately. Will come back to this when we have some time. |
|
H @ikq,
|
|
Hmm... I just did not consider this possibility before because I found INVITE/CANCEL/ACK specific code and properties in the Dialog (e.g. subscriber used different dialog states set). |
|
There is INVITE related code in Dialog because a dialog for INVITE method needs to behave in certain way, different to generic dialogs, but that's an implementation detail. Other clases should be able to create dialogs the same way RTCSession does. |
|
Hi Jose, I'll continue to test next week:
|
|
Testing of the current version has been completed successfully. |
|
subscribe authentication checked using special test. |
|
I see I should change debug/debugerror to logger... |
|
Hi @ikq, We are super busy lately. Please keep using your branch and update this PR whenever you find any issue/enhancement. Also, tests would accelerate the adoption. |
|
I already use this code for my work and so far no problem. Two browsers test can be taken from: |
|
@ikq, more than an external test I mean tests in JsSIP as part of this PR, testing the clases created here. |
|
Hi, is there some news? I'd like to test this functionality. |
IMHO it's stable code. The subscriber/notifier test can taken from https://github.com/ikq/subscribe_notify_test |
|
Hi, is there a specific reason why Subscriber and Notifier don't use the Contact header from the UA like RTCSession does? If the user provides a custom contact_uri in the UAConfiguration he would have to manually add it as a extra header to Subscriber and Notifier again, wouldn't he? |
I'd like to use the official repository, so I'd like if it will be merged ASAP |
Yes, I'm not using the Configuration.contact_uri In fact, I was in a hurry to do this work, and did not pay attention at all to that there is such a parameter in the configuration ! Let check, how the configuration used for INVITE: Thanks. P.S. |
|
@ikq if you don't mind external contributions i'd be willing to take a swing at writing unit tests for this project's test framework |
Thank you, I will gladly accept your help. I have provided an external test for 2 browsers: one is sending an SUBSCRIBE and the other is receiving it and sending a NOTIFY. Seems in unit test should be simulated 2 instances of JsSIP one send/other receive. |
@ikq Is there a specific reason to use Configuration.contact_uri? Why not just do it as in RTCSession, with |
|
Thank you markusatm for founding the problem. |
|
Hi, Yes, in order for this PR to be merged we need tests in JsSIP project. You don't need two JsSIP instances, just one instance and you should inject a transport that you control (a FAKE transport) that you use to send JsSIP UA SUBSCRIBE|NOTIFY messages and receive and check what comes from JsSIP. If you need some help please let us know. |
|
Hi,
The test SIP sequence is:
The unit test work silently, but if uncomment line JsSIP.debug.enable('JsSIP:*'); SUBSCRIBE and NOTIFY headers checking: |
273076d to
60a678e
Compare
| { | ||
| logger.debug('enqueue subscribe'); | ||
|
|
||
| this._queue.push({ body, headers: Utils.cloneArray(headers) }); |
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.
Nop, incoming SUBSCRIBE request will end up creating a Notifier, not a Subscriber. Subscriber is only created locally. Right?
c5160d4 to
6c1cfd7
Compare
6c1cfd7 to
faff4fe
Compare
|
The force-push-es are breaking the conversations which point to code. |
|
Sorry, do you prefer to stack up commits instead? |
I would prefer to see individual commits. This PR will be rebased before merging anyway. |
* Remove needless timeout * Reorder _terminateDialog * Reorder events * Revert unrelated change in RTCSession
|
Also please check the test error given by CI. |
0925d34 to
b4cbc1a
Compare
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.
I think these are my last comments.
| if (this._expires > 0) | ||
| { | ||
| // Set expires timer and time-stamp. | ||
| this._setExpiresTimer(); | ||
| } |
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.
IMO this should be moved to start() after responding the SUBSCRIBE. Otherwise we may send the terminated NOTIFY before responding the SUBSCRIBE which is odd and probably not spec compliant.
| let expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); | ||
|
|
||
| if (expires < 0) | ||
| { | ||
| expires = 0; | ||
| } |
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.
There could be a race condition here. Imagine that expires is 0 in line 277. The expires timer may run in the next loop iteration. We are going to:
- Send this NOTIFY with expires 0.
- In the next iteration, send another NOTFY with state terminate.
I know this is not likely to happen, but I would suggest having a private method such:
| let expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); | |
| if (expires < 0) | |
| { | |
| expires = 0; | |
| } | |
| let expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); | |
| // expires_timer is about to trigger. Clean up the timer and terminate. | |
| if (expires <= 0) | |
| { | |
| if (!this._expires_timer) | |
| { | |
| logger.error('expires timer is not set'); | |
| } | |
| clearTimeout(this._expires_timer); | |
| this.terminate(body, 'timeout'); | |
| } | |
| else | |
| { | |
| this._sendNotify([ `;expires=${expires}` ], body); | |
| } |
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.
Mmm, indeed this._expires_timer won't be set if Expires header field value in initial SUBSCRIBE is 0.
NOTE: This is handled in a previous comment.
| // Create dialog for normal and fetch-subscribe. | ||
| this._dialog = new Dialog(this, subscribe, 'UAS'); | ||
|
|
||
| if (this._expires > 0) |
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.
this._expires = parseInt(subscribe.getHeader('expires'));
Which means:
this._expireswould beNaNif Expires header is not present sincesubscribe.getHeader()will returnundefined. Check my proposal below.this._expireswould be negative if the value of Expires header is negative. We should handle that. Currently we are simply not setting the expires timer for negative value. IMO we should reject negatively if this happens, which can be done incheckSubscribe().
RFC6665 states that:
If no "Expires" header field is present in a SUBSCRIBE request, the
implied default MUST be defined by the event package being used.So constructor() should have a new NotifierOptions field defaultExpires which must be mandatory and used in case Expires header field is not set.
| // Create dialog for normal and fetch-subscribe. | ||
| this._dialog = new Dialog(this, subscribe, 'UAS'); |
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.
Being correct we should move dialog creation to the moment prior to sending the response in start().
I added Subscriber.js Notifier.js to JsSIP
I tried write them according JsSIP style and lint errors.
Please take a look and let me know what needs to be fixed.
I already see that *.d.ts files are missing.
The work still in progress: I want add to SUBSCRIBE Contact +sip.instance
as you do in REGISTER