1- using System . Net . WebSockets ;
1+ using System . Diagnostics ;
2+ using System . Net . WebSockets ;
23using System . Reactive . Linq ;
34using System . Reactive . Subjects ;
45using System . Text . Json ;
@@ -64,7 +65,7 @@ public async Task Start()
6465 //Filter General response
6566 var tt = client . MessageReceived . Select ( m => JsonSerializer . Deserialize < WebsocketResponse > ( m . ToString ( ) ) ) ;
6667
67- tt . Where ( e => e . Type == "ping" ) . Subscribe ( msg => SendRequest ( new WebsocketRequest ( "pong" ) ) ) ;
68+ tt . Where ( e => e . Type == WebsocketRequestTypes . PING ) . Subscribe ( msg => SendRequest ( new WebsocketRequest ( WebsocketRequestTypes . PONG ) ) ) ;
6869
6970 tt . Where ( e => ! string . IsNullOrEmpty ( e ? . Id ) ) . Subscribe ( r =>
7071 {
@@ -73,7 +74,7 @@ public async Task Start()
7374
7475 await client . Start ( ) ;
7576
76- var initRequest = new WebsocketRequest ( "connection_init" ) ;
77+ var initRequest = new WebsocketRequest ( WebsocketRequestTypes . CONNECTION_INIT ) ;
7778 if ( _graphClient . WSConnectionInitPayload is not null )
7879 {
7980 var initPayload = await _graphClient . WSConnectionInitPayload ( _graphClient ) ;
@@ -98,10 +99,10 @@ private string GetSubprotocolString()
9899 switch ( _graphClient . SubscriptionProtocol )
99100 {
100101 case SubscriptionProtocol . GraphQLWebSocket :
101- return "graphql-transport-ws" ;
102+ return SubscriptionProtocols . GraphQl_Transport_WS ;
102103
103104 case SubscriptionProtocol . ApolloWebSocket :
104- return "graphql-ws" ;
105+ return SubscriptionProtocols . GraphQl_WS ;
105106
106107 default :
107108 throw new Exception ( $ "{ _graphClient . SubscriptionProtocol } is unknown") ;
@@ -113,19 +114,20 @@ private string GetSubscribeCommand()
113114 switch ( _graphClient . SubscriptionProtocol )
114115 {
115116 case SubscriptionProtocol . GraphQLWebSocket :
116- return "subscribe" ;
117+ return SubscribeCommands . Subscribe ;
117118
118119 case SubscriptionProtocol . ApolloWebSocket :
119- return "start" ;
120+ return SubscribeCommands . Start ;
120121
121122 default :
122123 throw new Exception ( $ "{ _graphClient . SubscriptionProtocol } is unknown") ;
123124 }
124125 }
125126
126- private void LogMessage ( string message )
127+ private static void LogMessage ( string message )
127128 {
128- Console . WriteLine ( $ "{ message } - { DateTime . Now . ToString ( "T" ) } ") ;
129+ // Write logs to debug console
130+ Debug . WriteLine ( $ "{ message } - { DateTime . Now . ToString ( "T" ) } ") ;
129131 }
130132
131133 private void SendRequest ( WebsocketRequest request )
0 commit comments