Skip to content

Commit

Permalink
fix: multiple custom transport cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Sep 3, 2021
1 parent 5c9f2dc commit 78651fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/containers/Inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const Inspector: React.FC<IProps> = (props) => {

useEffect(() => {
if (selectedTransport !== undefined) {
setTransport(selectedTransport!);
setTransport(selectedTransport);
const s: IWebTransport = selectedTransport as IWebTransport;
if (s.schema !== undefined && s.schema !== true && s.schema !== false) {
setTransportOptions((s.schema.examples as ExampleObject[])[0]);
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/useTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getTransportFromType = async (
): Promise<Transport> => {
let localTransport: any;
const localTransportType = transports.find((value) => {
return value.type === transport.type;
return value.type === transport.type && value.name === transport.name;
});
if (localTransportType?.type === "websocket") {
localTransport = new WebSocketTransport(uri);
Expand Down Expand Up @@ -74,6 +74,7 @@ const getTransportFromType = async (
}
public close() {
intermediateTransport.unsubscribe();
intermediateTransport.close();
return intermediateTransport.sendData({
internalID: 0,
request: {
Expand Down Expand Up @@ -119,6 +120,10 @@ const useTransport: TUseTransport = (transports, url, defaultTransportType, tran
return localTransport.connect().then(() => {
setTransportConnected(true);
setTransport(localTransport);
}).catch((e) => {
localTransport.unsubscribe()
localTransport.close();
throw e;
});
};

Expand Down

0 comments on commit 78651fa

Please sign in to comment.