Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Not able to create new room using Matrix
Avatar
praveenkhare #1
Member since Aug 2015 · 4 posts
Group memberships: Members
Show profile · Link to this post
Subject: Not able to create new room using Matrix
Hi Alex,

I was trying to create persistent room using the Matrix sdk but to no vail.

I am getting "operation time out" error, looks like not able to enter room.
 
Below is the code snippet can you please look in to this and help me with the error/problem.

  1. void xmpp_OnLogin(object sender, Matrix.EventArgs ex)
  2. {
  3.     Jid room = new Jid("testMatrix@sb.com");
  4.  
  5.     MakeRoomPersistent(room);
  6.  
  7.     //mucManager.EnterRoomAsync(room, "chatadmin");
  8.  
  9.     //mucManager.RequestRoomConfigurationAsync(room);
  10.  
  11.  
  12.    
  13. }
  14.  
  15. private async void MakeRoomPersistent(Jid room)
  16. {
  17.     MucManager mm = new MucManager(xmpp);
  18.     try
  19.     {
  20.        
  21.         var retiq = await mm.EnterRoomAsync(room, "chatadmin", 30);
  22.  
  23.         var iq = await mm.RequestRoomConfigurationAsync(room, 30);
  24.  
  25.         if (iq.Type == Matrix.Xmpp.IqType.result) // only proceed on result
  26.         {
  27.             // Step 2 and 3, parsing the current config and
  28.             // creating the result is done in the same loop here.
  29.             var xdata = iq.Query.Element<Data>();
  30.             var xDataResult = new Data
  31.             {
  32.                 Type = FormType.submit
  33.             };
  34.  
  35.             foreach (var field in xdata.GetFields())
  36.             {
  37.                 var retField = new Field()
  38.                 {
  39.                     Type = field.Type, // keep the type
  40.                     Var = field.Var // keep the var
  41.                 };
  42.  
  43.                 // we are changing the muc#roomconfig_persistentroom only
  44.                 // other fields get copied only with the existing values          
  45.                 if (field.Var == "muc#roomconfig_persistentroom")
  46.                     retField.AddValue(true);
  47.                 else
  48.                     retField.AddValues(field.GetValues().ToArray());
  49.  
  50.                 xDataResult.AddField(retField);
  51.             }
  52.  
  53.             // Step 4, submit the changed configuration back to the server (room)
  54.             var submitIq = await mm.SubmitRoomConfigurationAsync(room, xDataResult);
  55.             if (submitIq.Type == Matrix.Xmpp.IqType.result)
  56.                 output = "success";
  57.             else
  58.                 output = "Error";
  59.         }
  60.     }
  61.     catch (TimeoutException te)
  62.     {
  63.         output = te.Message;
  64.     }
  65.     catch (Exception ex)
  66.     {
  67.         output = ex.Message;
  68.     }
  69.     finally
  70.     {
  71.         xmpp.Close();
  72.     }
  73.  
  74.     output = "nothing happened";
  75. }

Appreciate any help.
This post was edited 3 times, last on 2015-08-19, 23:42 by Alex.
Edit reason: added code formatting
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the problem could be that you execute this code in the OnLogin handler.

*Have you tried to execute it on a command buttom for example?
Avatar
praveenkhare #3
Member since Aug 2015 · 4 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex, I was able to create persistent room using agsXMPP..
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters: