Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Sep 16, 2024
1 parent c8e88db commit 264ad32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
6 changes: 0 additions & 6 deletions rpc/js/src/ClientChannel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AnyMessage, Message, MethodInfo, PartialMessage, ServiceType } from '@bufbuild/protobuf';
import { ContextValues, StreamResponse, Transport, UnaryResponse } from '@connectrpc/connect';
import { GrpcWebTransportOptions } from '@connectrpc/connect-web';
import { BaseChannel } from './BaseChannel';
import { ClientStream } from './ClientStream';
import { ConnectionClosedError } from './errors';
Expand All @@ -19,11 +18,6 @@ interface activeClienStream {
cs: ClientStream;
}

// TODO(erd): cross-platform
export type TransportFactory = (
init: GrpcWebTransportOptions
) => Transport

export class ClientChannel extends BaseChannel implements Transport {
private streamIDCounter = 0;
private readonly streams: Record<number, activeClienStream> = {};
Expand Down
20 changes: 12 additions & 8 deletions rpc/js/src/dial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {

import type { ContextValues, StreamResponse, Transport, UnaryResponse } from "@connectrpc/connect";
import { Code, ConnectError, createPromiseClient } from "@connectrpc/connect";
import { ClientChannel, TransportFactory } from './ClientChannel';
import { ClientChannel } from './ClientChannel';
import { ConnectionClosedError } from './errors';
import { Status } from './gen/google/rpc/status_pb';
import {
Expand All @@ -32,7 +32,7 @@ import {
} from './gen/proto/rpc/webrtc/v1/signaling_pb';
import { addSdpFields, newPeerConnectionForClient } from './peer';

import { createGrpcWebTransport, GrpcWebTransportOptions } from "@connectrpc/connect-web";
import { createGrpcWebTransport } from "@connectrpc/connect-web";
import { atob, btoa } from './polyfills';

export interface DialOptions {
Expand Down Expand Up @@ -94,6 +94,14 @@ export interface Credentials {
payload: string;
}

export type TransportFactory = (
init: TransportInitOptions
) => Transport

interface TransportInitOptions {
baseUrl: string;
}

// TODO(erd): correctly get grpc-web/node
export async function dialDirect(
address: string,
Expand Down Expand Up @@ -180,22 +188,20 @@ async function makeAuthenticatedTransportFactory(
return headers;
};
const extraMd = await getExtraHeaders();
return (opts: GrpcWebTransportOptions): Transport => {
return (opts: TransportInitOptions): Transport => {
return new authenticatedTransport(opts, defaultFactory, extraMd);
};
}

class authenticatedTransport implements Transport {
protected readonly opts: GrpcWebTransportOptions;
protected readonly transport: Transport;
protected readonly extraHeaders: Headers;

constructor(
opts: GrpcWebTransportOptions,
opts: TransportInitOptions,
defaultFactory: TransportFactory,
extraHeaders: Headers
) {
this.opts = opts;
this.extraHeaders = extraHeaders;
this.transport = defaultFactory(opts);
}
Expand Down Expand Up @@ -249,8 +255,6 @@ class authenticatedTransport implements Transport {
input,
contextValues)
}


}

export interface WebRTCConnection {
Expand Down

0 comments on commit 264ad32

Please sign in to comment.