Skip to content

Commit

Permalink
fix: allows notifications to be passed through custom transports
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Mar 21, 2021
1 parent 5e22cfb commit fe75d3f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/hooks/useTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JSONRPCError } from "@open-rpc/client-js/build/Error";
import { Dispatch, useEffect, useState } from "react";
import { HTTPTransport, WebSocketTransport, PostMessageWindowTransport, PostMessageIframeTransport } from "@open-rpc/client-js";
import { Transport } from "@open-rpc/client-js/build/transports/Transport";
import { IJSONRPCData } from "@open-rpc/client-js/build/Request";
import { IJSONRPCData, IJSONRPCNotificationResponse } from "@open-rpc/client-js/build/Request";
import { JSONSchema } from "@open-rpc/meta-schema";

export type TTransport = "http" | "websocket" | "postmessagewindow" | "postmessageiframe";
Expand Down Expand Up @@ -56,6 +56,9 @@ const getTransportFromType = async (
id: 0,
},
});
intermediateTransport.subscribe("notification", (data: IJSONRPCNotificationResponse) => {
this.transportRequestManager.transportEventChannel.emit("notification", data);
});
return results;
}
public sendData(data: IJSONRPCData): Promise<any> {
Expand All @@ -70,6 +73,7 @@ const getTransportFromType = async (
});
}
public close() {
intermediateTransport.unsubscribe();
return intermediateTransport.sendData({
internalID: 0,
request: {
Expand Down

0 comments on commit fe75d3f

Please sign in to comment.