Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ function createIPFSInterface(bootstrapNodes: string[], ipfsConfig: Options = def

function _maintainConnection() {
setTimeout(async () => {
if (!ipfsInitialised) {
return;
}
await ensureConnectedToBootstrapNodes();
_maintainConnection();
}, 10000);
Expand Down Expand Up @@ -179,12 +182,33 @@ function createIPFSInterface(bootstrapNodes: string[], ipfsConfig: Options = def
_resolveCachedPromises();
});

const stop = () => {
if (!node) {
throw new Error(`Not initialised`);
}

ipfsInitialised = false;
return node.stop();
};

const start = async () => {
if (!node) {
throw new Error('Not initialised');
}
await node.start();
ipfsInitialised = true;
_maintainConnection();
_resolveCachedPromises();
};

return {
getJSONData: <T>(cid: string) => _promiseWrapper<T>(getJSONData, cid),
sendJSONData: <T>(content: T) => _promiseWrapper<string>(sendJSONData, content),
sendData: (content: string | ArrayBuffer) => _promiseWrapper(sendData, content),
getData: (cid: string) => _promiseWrapper(getData, cid),
getNodes: () => _promiseWrapper(getNodes),
stop,
start,
loadingResult,
initResult,
startResult,
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ export interface IPFSInterface {
loadingResult: Promise<{ create: (options?: Options | undefined) => Promise<IPFS> }>;
initResult: Promise<{ ipfs: IPFS; CIDObj: typeof Multiformats.CID }>;
startResult: Promise<void>;
stop: () => Promise<void>;
start: () => Promise<void>;
}