dart_ws_grpc 0.0.2
dart_ws_grpc: ^0.0.2 copied to clipboard
A dart client for wsgrpc. Using Websocket as transport of grpc will make client stream and server stream call available for browser scripts.
example/main.dart
import 'dart:core';
import 'dart:convert';
import 'package:grpc/grpc_web.dart';
import 'package:dart_ws_grpc/api/ws/proto/ws.pb.dart';
import 'package:dart_ws_grpc/grpc_streaming.dart';
void main() async {
final channel = GrpcWebClientChannel.xhr(Uri.parse('http://127.0.0.1:80'));
final service = WsClient(channel);
String msg = ("Pong Pong Pong");
final request = Message(
topic: Topic.PONG,
channelId: Topic.PONG.toString(),
msgId: "ws.test",
payload: utf8.encode(msg),
);
service.streaming(request as Stream<Message>).listen((response) {
print(response.writeToJsonMap());
}, onError: (error) {
print(error.toString());
}, onDone: () => print('Closed connection to server.'));
}