/// <summary> /// Send message to HarmonyHub with UserAuthToken, wait for SessionToken /// </summary> /// <param name="userAuthToken"></param> /// <returns></returns> public string SwapAuthToken(string userAuthToken) { EnsureConnection(); var iqToSend = new IQ { Type = IqType.get, Namespace = "", From = "1", To = "guest" }; iqToSend.AddChild(HarmonyDocuments.LogitechPairDocument(userAuthToken)); iqToSend.GenerateId(); var iqGrabber = new IqGrabber(Xmpp); var iq = iqGrabber.SendIq(iqToSend, 5000); if (iq != null) { var match = IdentityRegex.Match(iq.InnerXml); if (match.Success) { return(match.Groups[1].ToString()); } } return(null); }
/// <summary> /// Send message to HarmonyHub with UserAuthToken, wait for SessionToken /// </summary> /// <param name="userAuthToken"></param> /// <returns></returns> public string SwapAuthToken(string userAuthToken) { var iqToSend = new IQ { Type = IqType.get, Namespace = "", From = "1", To = "guest" }; iqToSend.AddChild(HarmonyDocuments.LogitechPairDocument(userAuthToken)); iqToSend.GenerateId(); var iqGrabber = new IqGrabber(Xmpp); iqGrabber.SendIq(iqToSend, 10); WaitForData(5); return(_sessionToken); }
/// <summary> /// Send message to HarmonyHub, wait for SessionToken /// </summary> /// <returns>session token</returns> public async Task <string> CreateToken() { var iq = await RequestResponseAsync(HarmonyDocuments.LogitechPairDocument()).ConfigureAwait(false); var sessionData = GetData(iq); if (sessionData != null) { foreach (var pair in sessionData.Split(':')) { if (pair.StartsWith("identity")) { return(pair.Split('=')[1]); } } } throw new Exception("Wrong data"); }
/// <summary> /// Send message to HarmonyHub with UserAuthToken, wait for SessionToken /// </summary> /// <returns></returns> private async Task <string> PairAsync() { Trace.WriteLine("Harmony-logs: Pairing"); var response = await SendDocumentAsync(HarmonyDocuments.LogitechPairDocument()).ConfigureAwait(false); var sessionData = GetData(response.ResultIQ); if (sessionData != null) { foreach (var pair in sessionData.Split(':')) { if (pair.StartsWith("identity")) { return(pair.Split('=')[1]); } } } throw new Exception("Harmony: SwapAuthToken failed"); }