Skip to content

Commit fe75d3f

Browse files
committed
fix: allows notifications to be passed through custom transports
1 parent 5e22cfb commit fe75d3f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/hooks/useTransport.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { JSONRPCError } from "@open-rpc/client-js/build/Error";
33
import { Dispatch, useEffect, useState } from "react";
44
import { HTTPTransport, WebSocketTransport, PostMessageWindowTransport, PostMessageIframeTransport } from "@open-rpc/client-js";
55
import { Transport } from "@open-rpc/client-js/build/transports/Transport";
6-
import { IJSONRPCData } from "@open-rpc/client-js/build/Request";
6+
import { IJSONRPCData, IJSONRPCNotificationResponse } from "@open-rpc/client-js/build/Request";
77
import { JSONSchema } from "@open-rpc/meta-schema";
88

99
export type TTransport = "http" | "websocket" | "postmessagewindow" | "postmessageiframe";
@@ -56,6 +56,9 @@ const getTransportFromType = async (
5656
id: 0,
5757
},
5858
});
59+
intermediateTransport.subscribe("notification", (data: IJSONRPCNotificationResponse) => {
60+
this.transportRequestManager.transportEventChannel.emit("notification", data);
61+
});
5962
return results;
6063
}
6164
public sendData(data: IJSONRPCData): Promise<any> {
@@ -70,6 +73,7 @@ const getTransportFromType = async (
7073
});
7174
}
7275
public close() {
76+
intermediateTransport.unsubscribe();
7377
return intermediateTransport.sendData({
7478
internalID: 0,
7579
request: {

0 commit comments

Comments
 (0)