1
1
import 'dart:io' ;
2
+
2
3
import 'dart:convert' ;
3
4
import 'package:nostr_console/event_ds.dart' ;
4
5
import 'package:nostr_console/settings.dart' ;
5
6
import 'package:nostr_console/utils.dart' ;
6
7
import 'package:web_socket_channel/io.dart' ;
8
+ import 'package:web_socket_channel/src/exception.dart' ;
7
9
8
10
class Relay {
9
11
String url;
@@ -145,7 +147,7 @@ class Relays {
145
147
/*
146
148
* Send the given string to the given relay. Is used to send both requests, and to send evnets.
147
149
*/
148
- void sendRequest (String relayUrl, String request) {
150
+ void sendRequest (String relayUrl, String request) async {
149
151
if (relayUrl == "" ) {
150
152
if ( gDebug != 0 ) print ("Invalid or empty relay given" );
151
153
return ;
@@ -164,6 +166,15 @@ class Relays {
164
166
165
167
try {
166
168
IOWebSocketChannel fws2 = IOWebSocketChannel .connect (relayUrl);
169
+
170
+ try {
171
+ await fws2.ready;
172
+ } catch (e) {
173
+ // handle exception here
174
+ //print("Error: Failed to connect to relay $relayUrl . Got exception = |${e.toString()}|");
175
+ return ;
176
+ }
177
+
167
178
Relay newRelay = Relay (relayUrl, fws2, {}, 0 , 1 );
168
179
relays[relayUrl] = newRelay;
169
180
fws = fws2;
@@ -200,7 +211,11 @@ class Relays {
200
211
} on WebSocketException {
201
212
print ('WebSocketException exception for relay $relayUrl ' );
202
213
return ;
203
- } on Exception catch (ex) {
214
+ } on WebSocketChannelException {
215
+ print ('WebSocketChannelException exception for relay $relayUrl ' );
216
+ return ; // is presently not used/called
217
+ }
218
+ on Exception catch (ex) {
204
219
printWarning ("Invalid event\n " );
205
220
}
206
221
0 commit comments