/// <summary> //// Build a XmppXElement from a Xml string. /// </summary> /// <param name="xml">The Xml string.</param> /// <param name="removeWhitespace">if set to <c>true</c> whitespaces will be removed on parsing.</param> /// <returns></returns> public static XmppXElement LoadXml(string xml, bool removeWhitespace) { XmppXElement stanza = null; var sp = new StreamParser(); sp.OnStreamStart += (el) => stanza = el; sp.OnStreamElement += (el) => stanza.Add(el); sp.OnStreamError += (ex) => { throw ex; }; var bytes = System.Text.Encoding.UTF8.GetBytes(xml); sp.Write(bytes, 0, bytes.Length); return(stanza); }
internal XmppXElement DoAddTag(XNamespace ns, string tagname, string content, bool addFirst) { var newChild = new XmppXElement(ns, tagname); if (addFirst) { AddFirst(newChild); } else { Add(newChild); } if (content != null) { newChild.Value = content; } return(newChild); }
/// <summary> /// Disconnect VOIP/Video/Audio call. /// </summary> /// <param name="to">recipient jid</param> public void SendSessionTerminate(string to) { Matrix.Xmpp.Jingle.Jingle jIq = new Matrix.Xmpp.Jingle.Jingle(); jIq.Action = Matrix.Xmpp.Jingle.Action.SessionTerminate; jIq.GenerateSid(); string defaultNs = "urn:xmpp:jingle:1"; Matrix.Xml.XmppXElement eX = new Matrix.Xml.XmppXElement(defaultNs, "reason"); eX.Add(new Matrix.Xml.XmppXElement(defaultNs, "success")); jIq.Add(eX); Iq denyIq = new Iq(); denyIq.To = to; denyIq.From = this._jid; denyIq.Type = Matrix.Xmpp.IqType.Set; denyIq.Add(jIq); xmppClient.Send(denyIq); Log.Info(">session-terminate"); }
public void SendSessionTerminate(string to, string sid) { Matrix.Xmpp.Jingle.Jingle jIq = new Matrix.Xmpp.Jingle.Jingle(); jIq.Action = Matrix.Xmpp.Jingle.Action.SessionTerminate; jIq.Sid = sid; string defaultNs = "urn:xmpp:jingle:1"; Matrix.Xml.XmppXElement eX = new Matrix.Xml.XmppXElement(defaultNs, "reason"); eX.Add(new Matrix.Xml.XmppXElement(defaultNs, "success")); jIq.Add(eX); Iq denyIq = new Iq(); denyIq.To = to; denyIq.From = this.jid; denyIq.Type = Matrix.Xmpp.IqType.Set; denyIq.Add(jIq); Console.Write(denyIq.ToString()); xmppClient.Send(denyIq); }
/// <summary> /// Cast a XmppXElement to the given type. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="xmppXElement"></param> /// <returns></returns> public static T Cast <T>(this XmppXElement xmppXElement) where T : XmppXElement { return((T)xmppXElement); }
/// <summary> /// Check if a XmppXElement is of a given type. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="xmppXElement"></param> /// <returns></returns> public static bool OfType <T>(this XmppXElement xmppXElement) where T : XmppXElement { return(xmppXElement is T); }
/// <summary> /// Validates if a XmppXElement matches the given prerdicate /// </summary> /// <param name="xmppXElement"></param> /// <param name="predicate"></param> /// <returns></returns> public static bool IsMatch(this XmppXElement xmppXElement, Func <XmppXElement, bool> predicate) { return(predicate(xmppXElement)); }
public static bool OfTypeAny <T1, T2>(this XmppXElement xmppXElement) where T1 : XmppXElement where T2 : XmppXElement { return(xmppXElement.OfType <T1>() || xmppXElement.OfType <T2>()); }
public static JingleSdp FromSdp(string sdp) { JingleSdp jingle = new JingleSdp(); string[] s = sdp.Split(new string[] { "\nm=" }, StringSplitOptions.None); string sdpSession = s [0]; jingle.Session = new Matrix.Xml.XmppXElement("urn:xmpp:jingle:apps:sdp", "session"); jingle.Session.Text(sdpSession); System.Text.RegularExpressions.Regex regexUfrag = new System.Text.RegularExpressions.Regex("^a=ice-ufrag:(.+)"); System.Text.RegularExpressions.Regex regexPwd = new System.Text.RegularExpressions.Regex("^a=ice-pwd:(.+)"); System.Text.RegularExpressions.Regex regexFingerprint = new System.Text.RegularExpressions.Regex("^a=fingerprint:(.+)"); System.Text.RegularExpressions.Regex regexMedia = new System.Text.RegularExpressions.Regex("^(\\w+)\\b"); System.Text.RegularExpressions.MatchCollection matches; for (int i = 1; i < s.Length; i++) { string[] sdpLines = s [i].Split(new string[] { "\r\n" }, StringSplitOptions.None); string sdpContent = ""; string iceUfrag = ""; string icePwd = ""; string fingerprint = ""; string mediaName = ""; matches = regexMedia.Matches(sdpLines [0]); sdpLines [0] = "m=" + sdpLines [0]; mediaName = matches [0].Groups [1].Value; foreach (string sdpLine in sdpLines) { matches = regexUfrag.Matches(sdpLine); if (matches.Count > 0) { iceUfrag = matches [0].Groups[1].Value; continue; } matches = regexPwd.Matches(sdpLine); if (matches.Count > 0) { icePwd = matches [0].Groups[1].Value; continue; } matches = regexFingerprint.Matches(sdpLine); if (matches.Count > 0) { fingerprint = matches[0].Groups[1].Value; continue; } sdpContent += sdpLine + "\n"; } ContentSdp c = new ContentSdp(); c.Creator = "initiator"; c.Name = mediaName; c.Description = new Matrix.Xml.XmppXElement("urn:xmpp:jingle:apps:sdp", "description"); c.Description.Text(sdpContent); Matrix.Xmpp.Jingle.Transports.TransportIceUdp transport; transport = new Matrix.Xmpp.Jingle.Transports.TransportIceUdp(); transport.Pwd = icePwd; transport.Ufrag = iceUfrag; Matrix.Xml.XmppXElement xmlFingerprint = new Matrix.Xml.XmppXElement("urn:xmpp:tmp:jingle:apps:dtls:0", "fingerprint", new System.Xml.Linq.XAttribute("hash", "sha-256")); xmlFingerprint.Text(fingerprint); transport.Add(xmlFingerprint); c.TransportIceUdp = transport; // set ufrag // set pwd // add fingerprint //jingle.Add(c); jingle.Add(c); } Log.Verbose(jingle.ToString()); return(jingle); }