dart_ws_grpc 0.0.3 copy "dart_ws_grpc: ^0.0.3" to clipboard
dart_ws_grpc: ^0.0.3 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 {
  // Connect to grpc stream enpoint
  GrpcWebClientChannel channel = GrpcWebClientChannel.xhr(
      Uri.parse('http://localhost:80/ws.Ws/Streaming'));
  WsClient socket = WsClient(channel);

  // Create stream async
  Message ping = Message(payload: utf8.encode("Pong Pong Pong"));
  Stream<Message> stream = Stream<Message>.value(ping);

  // Add metadata header
  String token = "xxxx";
  Map<String, String> metaData = {"Authorization": "Bearer $token"};
  WebCallOptions callOptions = WebCallOptions(
      bypassCorsPreflight: true, withCredentials: false, metadata: metaData);

  // Listion event
  socket.streaming(stream, options: callOptions).listen((response) {
    print("...listening...");
    print(utf8.decode(response.payload));
  }, onError: (error) {
    print("...error...");
    print(error.toString());
  }, onDone: () => print('Closed connection to server.'));
}
1
likes
135
points
46
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A dart client for wsgrpc. Using Websocket as transport of grpc will make client stream and server stream call available for browser scripts.

Repository (GitLab)
View/report issues

License

MIT (license)

Dependencies

fixnum, flutter, grpc, protobuf

More

Packages that depend on dart_ws_grpc