Protobuf RPC for TypeScript and Go with streaming support.

Overview

Stream RPC

starpc implements Proto3 services (server & client) in both TypeScript and Go.

Supports client-to-server streaming RPCs in the web browser, currently not supported by any of the major RPC libraries.

The rpcproto file describes the protocol.

Can use any Stream multiplexer: defaults to libp2p-mplex over a WebSocket.

rpcstream supports sub-streams for per-component sub-services.

Usage

Starting with the protobuf-project repository on the "starpc" branch.

Use "git add" to add your new .proto files, then yarn gen to generate the TypeScript and Go code for them.

Examples

See the protobuf-project template on the "starpc" branch.

The demo/boilerplate project implements the Echo example below.

This repository uses protowrap, see the Makefile.

Protobuf

The following examples use the echo protobuf sample.

syntax = "proto3";
package echo;

// Echoer service returns the given message.
service Echoer {
  // Echo returns the given message.
  rpc Echo(EchoMsg) returns (EchoMsg);
  // EchoServerStream is an example of a server -> client one-way stream.
  rpc EchoServerStream(EchoMsg) returns (stream EchoMsg);
  // EchoClientStream is an example of client->server one-way stream.
  rpc EchoClientStream(stream EchoMsg) returns (EchoMsg);
  // EchoBidiStream is an example of a two-way stream.
  rpc EchoBidiStream(stream EchoMsg) returns (stream EchoMsg);
}

// EchoMsg is the message body for Echo.
message EchoMsg {
  string body = 1;
}

Go

This example demonstrates both the server and client:

// construct the server
echoServer := &echo.EchoServer{}
mux := srpc.NewMux()
if err := echo.SRPCRegisterEchoer(mux, echoServer); err != nil {
	t.Fatal(err.Error())
}
server := srpc.NewServer(mux)

// create an in-memory connection to the server
openStream := srpc.NewServerPipe(server)

// construct the client
client := srpc.NewClient(openStream)

// construct the client rpc interface
clientEcho := echo.NewSRPCEchoerClient(client)
ctx := context.Background()
bodyTxt := "hello world"
out, err := clientEcho.Echo(ctx, &echo.EchoMsg{
	Body: bodyTxt,
})
if err != nil {
	t.Fatal(err.Error())
}
if out.GetBody() != bodyTxt {
	t.Fatalf("expected %q got %q", bodyTxt, out.GetBody())
}

TypeScript

See the ts-proto README to generate the TypeScript for your protobufs.

For an example of Go <-> TypeScript interop, see the integration test. For an example of TypeScript <-> TypeScript interop, see the e2e test.

Supports any AsyncIterable communication channel. DuplexConn, MessagePortConn, and WebSocketConn use js-libp2p-mplex to multiplex streams, but any multiplexer can be used.

This example demonstrates both the server and client:

import { pipe } from 'it-pipe'
import { createHandler, createMux, Server, Client, Conn } from 'srpc'
import { EchoerDefinition, EchoerServer, runClientTest } from 'srpc/echo'

const mux = createMux()
const echoer = new EchoerServer()
mux.register(createHandler(EchoerDefinition, echoer))
const server = new Server(mux)

const clientConn = new Conn()
const serverConn = new Conn(server)
pipe(clientConn, serverConn, clientConn)
const client = new Client(clientConn.buildOpenStreamFunc())

console.log('Calling Echo: unary call...')
let result = await demoServiceClient.Echo({
  body: 'Hello world!',
})
console.log('success: output', result.body)

const clientRequestStream = new Observable<EchoMsg>(subscriber => {
  subscriber.next({body: 'Hello world from streaming request.'})
  subscriber.complete()
})

console.log('Calling EchoClientStream: client -> server...')
result = await demoServiceClient.EchoClientStream(clientRequestStream)
console.log('success: output', result.body)

WebSocket

One way to integrate Go and TypeScript is over a WebSocket:

import { WebSocketConn } from 'srpc'
import { EchoerClientImpl } from 'srpc/echo'

const ws = new WebSocket('ws://localhost:5000/demo')
const channel = new WebSocketConn(ws)
const client = channel.buildClient()
const demoServiceClient = new EchoerClientImpl(client)

const result = await demoServiceClient.Echo({
  body: "Hello world!"
})
console.log('output', result.body)

Attribution

protoc-gen-go-starpc is a heavily modified version of protoc-gen-go-drpc.

Be sure to check out drpc as well: it's compatible with grpc, twirp, and more.

Uses vtprotobuf to generate Protobuf marshal / unmarshal code.

Support

Starpc is built & supported by Aperture Robotics, LLC.

Community contributions and discussion are welcomed!

Please open a GitHub issue with any questions / issues.

... or feel free to reach out on Matrix Chat or Discord.

You might also like...

Full-Stack Instgram Clone using MERN Stack and Socket.io

Full-Stack Instgram Clone using MERN Stack and Socket.io

Instagram MERN Full-Stack Instgram Clone using MERN Stack and Socket.io Visit Now 🚀 🖥️ Tech Stack Frontend: Backend: Realtime Communication: Cloud S

Dec 27, 2022

Website to display chats and gifts in realtime from your TikTok LIVE stream. Demo project for TikTok-Live-Connector library.

Website to display chats and gifts in realtime from your TikTok LIVE stream. Demo project for TikTok-Live-Connector library.

TikTok-Chat-Reader A chat reader for TikTok LIVE utilizing TikTok-Live-Connector and Socket.IO to forward the data to the client. This demo project us

Dec 31, 2022

WebRTC based peer to peer video calling and messaging web app build with MERN stack.

talkhouse WebRTC based peer to peer video calling and messaging web app build with MERN stack. Demo Libraries used React for frontend Socket.io as sig

Nov 26, 2022

Node.js library to receive live stream chat events like comments and gifts in realtime from TikTok LIVE.

TikTok-Live-Connector A Node.js library to receive live stream events such as comments and gifts in realtime from TikTok LIVE by connecting to TikTok'

Jan 4, 2023

This server is made to serve the MSN-Messenger app develop by Gabriel Godoy. This applications is capable to register users and messages in order implements a real time chat.

📱 MSN-Messenger-Server Node.js server for real time chat About | Installations | How to Use | Documentation | Technologies | License 😁 About This se

Dec 20, 2022

PondSocket is a fast, minimalist and bidirectional socket framework for NodeJS.

PondSocket PondSocket is a fast, minimalist and bidirectional socket framework for NodeJS. Pond allows you to think of each action during a sockets li

Nov 1, 2022

🚀🚀🚀 Nuxt3 client and server communication

Nuxt 3 Minimal Starter Look at the nuxt 3 documentation to learn more. Setup Make sure to install the dependencies: # yarn yarn install # npm npm ins

Dec 19, 2022

Patronum: Ethereum RPC proxy that verifies RPC responses against given trusted block hashes

Patronum: Ethereum RPC proxy that verifies RPC responses against given trusted block hashes

Patronum Ethereum RPC proxy that verifies RPC responses against given trusted block hashes. Currently, most of the DAPPs and Wallets interact with Eth

Dec 7, 2022

Webrtc, & web socket based streaming live video streaming and chatting platform. Written in Node, Typescript, and Javascript!

Live Streaming!! Welcome to my implementation of live streaming along with real time chat. I'm going to make a live streaming platform that will supoo

Nov 23, 2022

Like JSON-RPC, but supports streaming.

Like JSON-RPC, but supports streaming.

Earthstar Streaming RPC Similar to JSON-RPC, but also supports streaming (soon). Written to be used in Earthstar (github, docs). Table of Contents Usa

Feb 10, 2022

A repository to generate the fake json data from protobuf.

Mock Protobuf A command-line tool to mock protobuf! Table of Contents Install Usage Generate Mock Data Mock Server Mock Server Data Filter Include Fil

Dec 7, 2022

Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

May 18, 2022

Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

May 3, 2022

Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

Jan 3, 2023

JSON-RPC 2.0 implementation over WebSockets for Node.js and JavaScript/TypeScript

JSON-RPC 2.0 implementation over WebSockets for Node.js and JavaScript/TypeScript

WebSockets for Node.js and JavaScript/TypeScript with JSON RPC 2.0 support on top. About The rpc-websockets library enables developers to easily imple

Dec 21, 2022

A fixed-width file format toolset with streaming support and flexible options.

fixed-width A fixed-width file format toolset with streaming support and flexible options. Features Flexible: lot of options Zero dependencies: small

Jul 14, 2022

Query for CSS brower support data, combined from caniuse and MDN, including version support started and global support percentages.

css-browser-support Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentage

Nov 2, 2022

RPC-like client, contract, and server implementation for a pure REST API

RPC-like client, contract, and server implementation for a pure REST API

ts-rest RPC-like client and server helpers for a magical end to end typed experience Introduction ts-rest provides an RPC-like client side interface o

Dec 30, 2022
Comments
  • srpc: add server support to typescript

    srpc: add server support to typescript

    This issue tracks:

    • Implement the server side in TypeScript (currently only has client).
    • Add ts-jest tests for TypeScript client + server integration.
    • Add an integration test for Go -> TypeScript with Go as the client.
    enhancement 
    opened by paralin 2
  • multiplexer: switch from mplex to yamux

    multiplexer: switch from mplex to yamux

    https://github.com/libp2p/js-libp2p/issues/1152

    According to go-mplex README, mplex is now deprecated, and yamux is recommended.

    Waiting support for Yamux in TypeScript before switching fully.

    enhancement 
    opened by paralin 1
  • Fix importing protobuf file paths

    Fix importing protobuf file paths

    import { OtherMessage } from '../../../../github.com/aperturerobotics/protobuf-project/example/other/other'
    

    Currently when importing another message, an import path like this is generated by ts-proto.

    See https://github.com/stephenh/ts-proto/issues/596 and https://github.com/stephenh/ts-proto/pull/597

    bug 
    opened by paralin 1
  • Change importsNotUsedAsValues to error

    Change importsNotUsedAsValues to error

    Change "importsNotUsedAsValues" to "error":

    • https://github.com/stephenh/ts-proto/issues/594

    Currently sometimes causes issues with the ts-proto generated code.

    enhancement 
    opened by paralin 0
Owner
Aperture Robotics
Modular peer-to-peer applications that run anywhere.
Aperture Robotics
Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js

ws: a Node.js WebSocket library ws is a simple to use, blazing fast, and thoroughly tested WebSocket client and server implementation. Passes the quit

WebSockets 19.2k Jan 4, 2023
Simple realtime chat application made by NodeJS, Express, Socket.io and Vanilla Javascript. This project is made to discover socket.io and understand its basic features.

LearnByChat App Simple realtime chat application made with NodeJS, Express, Socket.io and Vanilla Javascript. This project is made to discover socket.

Ayoub Saouidi 1 Dec 19, 2021
A node.js module for websocket server and client

Nodejs Websocket A nodejs module for websocket server and client How to use it Install with npm install nodejs-websocket or put all files in a folder

Guilherme Souza 719 Dec 13, 2022
Standards-compliant WebSocket client and server

faye-websocket This is a general-purpose WebSocket implementation extracted from the Faye project. It provides classes for easily building WebSocket s

null 588 Dec 23, 2022
Lightweight WebSocket lib with socket.io-like event handling, requests, and channels

ws-wrapper Lightweight and isomorphic Web Socket lib with socket.io-like event handling, Promise-based requests, and channels. What? Much like Socket.

Blake Miner 70 Dec 23, 2022
simple chat app created with nextjs, express, tailwindcss, and WebSockets

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Erfan Hanifezade 10 Sep 10, 2022
Create a Real-time Chat App using React and Socket.io

React And Socket.io ChatApp MIT Licence MIT License Copyright (c) 2021 Ali Ahmad Permission is hereby granted, free of charge, to any person obtaining

Ali Ahmad 2 Jan 10, 2022
A simple web app that people can chat and send images into.

Typsnd Typsnd. Type, send. It's as simple as that. Typsnd is a simple web app that people can chat and send images into. It is based on Express.JS, No

null 10 Nov 10, 2022
An example about web socket with .net 3.1 and react

Websocket Example This is a real time app example which is using web socket, dot net core and react. Project Case You are a factory manager and you ha

Samet Yazıcı 5 Jan 11, 2022
soketi is your simple, fast, and resilient open-source WebSockets server

soketi soketi is your simple, fast, and resilient open-source WebSockets server. ?? Blazing fast speed ⚡ The server is built on top of uWebSockets.js

Soketi 3.2k Jan 4, 2023