DaveInNYC
unread,Nov 29, 2009, 12:20:42 PM11/29/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jabber-net
Because of the asynchronous nature of receiving disco information, I
have to use a convoluted series of callbacks to get to the information
I need, in this case the JID of the MUC server. Below is my code; am I
missing some simpler way to do this? Thanks.
void JabberClient_OnAuthenticate(object sender)
{
DiscoManager.BeginGetFeatures(null, (a, b, c) => OnGetFeatures(),
null);
}
void OnGetFeatures()
{
DiscoManager.Root.AddItemsCallback(null, (a, b, c) =>
OnRootChildrenCreated(), null);
}
int _rootChildrenPending;
void OnRootChildrenCreated()
{
_rootChildrenPending = DiscoManager.Root.Children.Count;
foreach (DiscoNode child in DiscoManager.Root.Children)
{
child.AddFeatureCallback(DiscoManager, (a, b, c) =>
OnRootChildPopulated(), null);
}
}
void OnRootChildPopulated()
{
lock (DiscoManager.Root)
{
_rootChildrenPending--;
if (_rootChildrenPending == 0)
{
SetMucId();
}
}
}
private WaitableValue<JID> MucId { get; set; }
private void SetMucId()
{
JID mucComponent = null;
foreach (DiscoNode component in DiscoManager.Root.Children)
{
if (component.HasFeature(jabber.protocol.URI.MUC))
{
mucComponent = component.JID;
break;
}
}
MucId.Value = mucComponent;
}