watch method
Implementation
Future<AvandaStream?> watch([WatchCallback? callback]) async {
if (queryTree.n == null) {
throw "Specify service to send request to";
}
var uri = (Avanda.config.wsUrl ?? Avanda.config.rootUrl);
if (uri == null) {
throw "Specify the server root URL in Avanda.setConfig() function";
}
String link = toLink();
var url = Uri.parse(uri);
var endpoint =
(Avanda.config.secureWebSocket == true ? 'wss://' : 'ws://') + url.host;
if (url.hasPort) {
endpoint += (':' + url.port.toString());
}
endpoint += '/watch?query=' + link;
if (postData != null && postData!.isNotEmpty) {
endpoint += '&data=' + jsonEncode(postData);
}
var controller = WSController(wsUrl: endpoint, headers: headers);
var streamController = controller.streamController;
var stream = AvandaStream(
stream: streamController.stream
.map((event) => Response(ResponseStruct.fromJson(jsonDecode(event)))),
wsSink: streamController.sink,
controller: controller,
);
return stream;
}