From 343e3cb94c2985078f3e2e0510a024ecfa58b87f Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Wed, 29 Apr 2015 17:31:22 +0000 Subject: SkypeWeb: TRouter support part 2. git-svn-id: http://svn.miranda-ng.org/main/trunk@13249 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/skype_trouter.cpp | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'protocols/SkypeWeb/src/skype_trouter.cpp') diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index 9ff87a16f8..b5970f8e75 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -27,11 +27,12 @@ void CSkypeProto::OnCreateTrouter(const NETLIBHTTPREQUEST *response) ptrA connId(mir_t2a(ptrT(json_as_string(json_get(root, "connId"))))); ptrA instance(mir_t2a(ptrT(json_as_string(json_get(root, "instance"))))); ptrA socketio(mir_t2a(ptrT(json_as_string(json_get(root, "socketio"))))); - + ptrA url(mir_t2a(ptrT(json_as_string(json_get(root, "url"))))); setString("Trouter_ccid", ccid); setString("Trouter_connId", connId); setString("Trouter_instance", instance); setString("Trouter_socketio", socketio); + setString("Trouter_url", url); SendRequest(new CreateTrouterPoliciesRequest(TokenSecret, connId), &CSkypeProto::OnTrouterPoliciesCreated); } @@ -71,6 +72,21 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response) CMStringA szToken = data.Tokenize(":", iStart).Trim(); setString("Trouter_SessId", szToken); m_hTrouterThread = ForkThreadEx(&CSkypeProto::TRouterThread, 0, NULL); + SendRequest(new RegisterTrouterRequest(TokenSecret, ptrA(getStringA("Trouter_url")))); +} + +void CSkypeProto::OnHealth(const NETLIBHTTPREQUEST *response) +{ + ptrA socketIo(getStringA("Trouter_socketio")); + ptrA connId(getStringA("Trouter_connId")); + ptrA st(getStringA("Trouter_st")); + ptrA se(getStringA("Trouter_se")); + ptrA instance(getStringA("Trouter_instance")); + ptrA ccid(getStringA("Trouter_ccid")); + ptrA sessId(getStringA("Trouter_SessId")); + ptrA sig(getStringA("Trouter_sig")); + + SendRequest(new GetTrouterRequest(socketIo, connId, st, se, sig, instance, ccid), &CSkypeProto::OnGetTrouter); } void CSkypeProto::TRouterThread(void*) @@ -104,12 +120,23 @@ void CSkypeProto::TRouterThread(void*) if (response->resultCode != 200) { - errors++; + SendRequest(new HealthTrouterRequest(ccid), &CSkypeProto::OnHealth); + break; } if (response->pData) { - + char *json = strstr(response->pData, "{"); + + if (json == NULL) continue; + + JSONROOT root(json); + ptrA szBody(mir_t2a(ptrT(json_as_string(json_get(root, "body"))))); + JSONNODE *headers = json_get(root, "headers"); + JSONROOT jsonBody(szBody); + ptrT displayname(json_as_string(json_get(jsonBody, "displayname"))); + ptrT uid(json_as_string(json_get(jsonBody, "conversationId"))); + ShowNotification(displayname, TranslateT("Incoming call")); } m_TrouterConnection = response->nlc; @@ -120,7 +147,6 @@ void CSkypeProto::TRouterThread(void*) if (!isTerminated) { debugLogA(__FUNCTION__": unexpected termination; switching protocol to offline"); - //SetStatus(ID_STATUS_OFFLINE); } m_hTrouterThread = NULL; m_TrouterConnection = NULL; -- cgit v1.2.3