InnovateAsterisk / Browser-Phone

A fully featured browser based WebRTC SIP phone for Asterisk
https://www.innovateasterisk.com
GNU Affero General Public License v3.0
472 stars 240 forks source link

Subscribe to multiple Asterisk hints #363

Open vieridipaola opened 1 year ago

vieridipaola commented 1 year ago

Hi,

Would it be possible for Browser Phone to subscribe to more than one hint?

Suppose I have something like this:

DND4055@to-extension: Custom:DND4055        State:Busy            Presence:not_set         Watchers  0
4055@default        : PJSIP/4055            State:Unavailable     Presence:available       Watchers  2

Can I use Browser Phone to subscribe to both 4055 and DND4055 which is a Custom Device State? The DND custom device state could then be displayed somehow as another status, or the admin user could decide whether to combine this state with other states and custom set buddyObj.devState.

For instance, in this example if I know that 4055 has State:Unavailable and DND4055 has State:Busy it would make sense to custom set buddyObj.devState = "dotOffline". However, if 4055 has State:Idle and DND4055 has State:Busy it would make sense to also custom set buddyObj.devState = "dotOffline" or dotOnHold or whatever. At least it makes sense in my organization...

Just a thought.

InnovateAsterisk commented 1 year ago

The way I understand it from here: https://wiki.asterisk.org/wiki/display/AST/Extension+State+and+Hints

Asterisk can subscribe to the device and the custom presence like this:

exten = 4055,hint,PJSIP/4055,CustomPresence:DND4055

Multiple devices can be mapped to an extension by providing an ampersand delimited list. A presence state ID is set after the device state IDs. If set with only a presence state provider you must be sure to include a blank field after the hint as in the example for extension 6005.

InnovateAsterisk commented 1 year ago

I'm not sure what the outcome of this is, but I would imagine a watcher would be informed of both device state (Ready, In a Call, etc), and "DND", "In a Meeting" etc.

It could easily be relayed to the UI by looking at the Ready (online/Idle) device state, and then seeing if any other condition (in the custom presence) should warn the watchers, like say DND, that would override the "Ready" device state.

Remember, Ready just means the device is online/idle, the question of "should i bother this person or not?" is the presence, and this mostly applied to the "Ready" state, because remember if the the device sate is anything other than "Ready"... well, you can try call that person, but im not sure if they will answer.

InnovateAsterisk commented 1 year ago

How are you setting the custom presence? That should probably show in some sort of UI on your users side, right?

There is a DND option, but this doesn't currently send anything to the server... should we look at some sort of custom OPTIONS,MESSAGE or INFO packet that get sent to the server, and interpreted?

Maybe you can subscribe to yourself, and your own status, can be updated in the UI and synced with the DND status of the UserAgent. This way you can see across devices for your own state. I'm pretty sure if possible to subscribe to your self.

vieridipaola commented 1 year ago

I "solved" the CustomPresence issue referred to here: https://github.com/InnovateAsterisk/Browser-Phone/issues/355#issuecomment-1316730384

That is a Digium-specific presence solution where "presence" is a "user/extension state".

I'm happy with the device/presence I managed to mix in the other post.

In this post however I was considering only what Asterisk calls "device states" and "custom device states".

I've brought this up in the Asterisk forum here: https://community.asterisk.org/t/custom-hints-device-state/94657

I might be wrong, but I only see the possibility of subscribing to a custom device state "separately" because a combined state such as PJSIP/123&Custom:DND123 will give me a reading that I don't want (in my case).

Some might argue that DND should not be considered a "device" state but a user state (presence). In any case, Asterisk Custom Device states (which have nothing to do with CustomPresence) can be created for whatever one likes. Subscribing to them and properly handling them is another story.

InnovateAsterisk commented 1 year ago

I'm inclined to say that DND is a "human" state (for the lack of another word), in other words it speaks to your availability, not necessarily to the physical status of the device, like "is it actually plugged in?".

But that being said, DND is also a "state" or "status" that you want watcher to know about... so it should be part of the information relayed back to the watcher. Maybe i'm not understanding what you want, but from the sample in this post: https://github.com/InnovateAsterisk/Browser-Phone/issues/355#issuecomment-1311372117 all the correct information is returned:

<?xml version="1.0" encoding="UTF-8"?>
<presence entity="sip:4155@127.0.0.1:8090;transport=ws" xmlns="urn:ietf:params:xml:ns:pidf" xmlns:dm="urn:ietf:params:xml:ns:pidf:data-model" xmlns:rpid="urn:ietf:params:xml:ns:pidf:rpid">
 <note>Ready</note>
 <tuple id="4155">
  <status>
   <basic>open</basic>
  </status>
  <contact priority="1">sip:web4053@xmpp.domain.org</contact>
 </tuple>
 <tuple id="digium-presence">
  <status>
   <digium_presence type="dnd" />
  </status>
 </tuple>
 <dm:person />
</presence>

You get <basic>open</basic> meaning the device is online, and you get <digium_presence type="dnd" /> meaning that you can override the online status, and rather say DND.

InnovateAsterisk commented 1 year ago

Something I noticed on the forum, you are using &, but the docs say "A presence state ID is set after the device state IDs. "

exten = 6004,hint,SIP/Diane,CustomPresence:Diane
vieridipaola commented 1 year ago

Yes, CustomPresence works fine, but that's a different thing, and it's specific to Digium/Sangoma. As I said earlier I sort of solved my problem with CustomPresence as I get both <basic>open</basic> and <digium_presence type="dnd" />, and I deal with those in web_hook_on_notify.

I initially posted in the Asterisk forum talking about "Custom Device States". Asterisk deals with those by passing "Custom:" to DEVICE_STATE(). In that scenario one can can add with & a Custom: device state like so:

exten = 6004,hint,SIP/Diane&Custom:DNDDiane

That's one thing, and it doesn't work as I'd like it to work as mentioned in the first part of my Asterisk Forum post.

I then deviated my attention to CustomPresence in that same Asterisk Forum thread because I could not make the Custom Device State work as I wanted it to.

So yes, CustomPresence "works for me", and I could settle with that.

However, I am assuming that I will always use Digium-compatible user agents. I can do so with Browser Phone -- no problem. Nonetheless, I have other types of softphones and hardphones in the network that are not Digium-compatible. I have no idea if that extra tuple info will eventually bite back, and cause trouble. CustomPresence for Digium-only UAs is not part of any RFC.

So, if I were to use only Custom Device States (and not use CustomPresence) then I would have the added problem of how to subscribe to the proper hint. As PJSIP/123&Custom:DND123 would not work I'm supposing that I could subscribe to both PJSIP/123 and Custom:DND123 if there were an event handler and 2 different UI elements to update the state with (one for PJSIP and the other for "Custom:DND").

I'm not sure I've been 100% clear in my explanation so here are some references.

About DEVICE STATES:

https://wiki.asterisk.org/wiki/display/AST/Device+State https://kb.smartvox.co.uk/asterisk/how-it-works/custom-device-state-blf/ http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/usingCustomDeviceStates.html

About Presence State (Digium-specific):

https://wiki.asterisk.org/wiki/display/AST/Presence+State

To boil it down to a simpler question: when adding a buddy in Browser Phone one can specify the subscription extension. It might be possible to add more than one subscription extension when adding a buddy. One or more different subscription events could then be sent.

If it's too complicated then we can just let it be. For now I'm OK with just CustomPresence. Your call.