@@ -94,7 +94,7 @@ public async Task<int> FinishNewDeviceRegistration(CancellationToken token, Stri
94
94
{
95
95
ConfirmCodeMessage javaJson = new ConfirmCodeMessage ( signalingKey , supportsSms , fetchesMessages , registrationId , deviceName ) ;
96
96
string json = JsonUtil . ToJson ( javaJson ) ;
97
- string responseText = await MakeServiceRequestAsync ( string . Format ( DEVICE_PATH , code ) , "PUT" , json ) ;
97
+ string responseText = await MakeServiceRequestAsync ( token , string . Format ( DEVICE_PATH , code ) , "PUT" , json ) ;
98
98
DeviceId response = JsonUtil . FromJson < DeviceId > ( responseText ) ;
99
99
return response . NewDeviceId ;
100
100
}
@@ -479,9 +479,10 @@ public ContactTokenDetails GetContactTokenDetails(string contactToken)// throws
479
479
}
480
480
}
481
481
482
- public TurnServerInfo GetTurnServerInfo ( )
482
+ public async Task < TurnServerInfo > GetTurnServerInfo ( CancellationToken token )
483
483
{
484
- throw new NotImplementedException ( ) ;
484
+ string response = await MakeServiceRequestAsync ( token , TURN_SERVER_INFO , "GET" , null ) ;
485
+ return JsonUtil . FromJson < TurnServerInfo > ( response ) ;
485
486
}
486
487
487
488
public void SetSoTimeoutMillis ( long soTimeoutMillis )
@@ -615,18 +616,19 @@ private string MakeServiceRequest(string urlFragment, string method, string body
615
616
{
616
617
try
617
618
{
618
- return MakeServiceRequestAsync ( urlFragment , method , body ) . Result ;
619
+ var dummy = new CancellationTokenSource ( ) ;
620
+ return MakeServiceRequestAsync ( dummy . Token , urlFragment , method , body ) . Result ;
619
621
}
620
622
catch ( AggregateException e )
621
623
{
622
624
throw e . InnerException ;
623
625
}
624
626
}
625
627
626
- private async Task < string > MakeServiceRequestAsync ( string urlFragment , string method , string body )
628
+ private async Task < string > MakeServiceRequestAsync ( CancellationToken token , string urlFragment , string method , string body )
627
629
//throws NonSuccessfulResponseCodeException, PushNetworkException
628
630
{
629
- HttpResponseMessage connection = GetServiceConnection ( urlFragment , method , body ) ;
631
+ HttpResponseMessage connection = await GetServiceConnectionAsync ( token , urlFragment , method , body ) ;
630
632
HttpStatusCode responseCode ;
631
633
string responseMessage ;
632
634
string responseBody ;
@@ -719,7 +721,7 @@ private bool Func(HttpRequestMessage a, X509Certificate2 b, X509Chain c, SslPoli
719
721
return true ;
720
722
}
721
723
722
- private HttpResponseMessage GetServiceConnection ( string urlFragment , string method , string body )
724
+ private async Task < HttpResponseMessage > GetServiceConnectionAsync ( CancellationToken token , string urlFragment , string method , string body )
723
725
{
724
726
try
725
727
{
@@ -753,7 +755,6 @@ private HttpResponseMessage GetServiceConnection(string urlFragment, string meth
753
755
if ( body != null )
754
756
{
755
757
content = new StringContent ( body , Encoding . UTF8 , "application/json" ) ;
756
- Debug . WriteLine ( body ) ;
757
758
}
758
759
else
759
760
{
@@ -762,16 +763,16 @@ private HttpResponseMessage GetServiceConnection(string urlFragment, string meth
762
763
switch ( method )
763
764
{
764
765
case "POST" :
765
- return connection . PostAsync ( uri , content ) . Result ;
766
+ return await connection . PostAsync ( uri , content , token ) ;
766
767
767
768
case "PUT" :
768
- return connection . PutAsync ( uri , content ) . Result ;
769
+ return await connection . PutAsync ( uri , content , token ) ;
769
770
770
771
case "DELETE" :
771
- return connection . DeleteAsync ( uri ) . Result ;
772
+ return await connection . DeleteAsync ( uri , token ) ;
772
773
773
774
case "GET" :
774
- return connection . GetAsync ( uri ) . Result ;
775
+ return await connection . GetAsync ( uri , token ) ;
775
776
776
777
default :
777
778
throw new Exception ( "Unknown method: " + method ) ;
0 commit comments