🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

ipfs-message-port-server

Package Overview
Dependencies
Maintainers
4
Versions
286
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipfs-message-port-server

IPFS server library for exposing IPFS node over message port

0.15.1
latest
Source
npm
Version published
Weekly downloads
15
-69.39%
Maintainers
4
Weekly downloads
 
Created
Source

⛔️ DEPRECATED: js-IPFS has been superseded by Helia

📚 Learn more about this deprecation or how to migrate

⚠️ If you continue using this repo, please note that security fixes will not be provided

ipfs-message-port-server

ipfs.tech Discuss codecov CI

IPFS server library for exposing IPFS node over message port

Table of contents

Install

$ npm i ipfs-message-port-server

Browser <script> tag

Loading this module through a script tag will make it's exports available as IpfsMessagePortServer in the global namespace.

<script src="https://unpkg.com/ipfs-message-port-server/dist/index.min.js"></script>

Usage

This library can wrap a JS IPFS node and expose it over the message channel. It assumes ipfs-message-port-client on the other end, however it is not strictly necessary anything complying with the wire protocol will do.

It provides following API subset:

The server is designed to run in a SharedWorker (although it is possible to run it in the other JS contexts). The example below illustrates running a js-ipfs node in a SharedWorker and exposing it to all connected ports

import { create } from 'ipfs'
import { IPFSService, Server } from 'ipfs-message-port-server'

const main = async () => {
  const connections = []
  // queue connections that occur while node was starting.
  self.onconnect = ({ports}) => connections.push(...ports)

  const ipfs = await create()
  const service = new IPFSService(ipfs)
  const server = new Server(service)

  // connect new ports and queued ports with the server.
  self.onconnect = ({ports}) => server.connect(ports[0])
  for (const port of connections.splice(0)) {
    server.connect(port)
  }
}

main()

Notes on Performance

Since the data sent over the message channel is copied via the structured cloning algorithm it may lead to suboptimal results (especially with large binary data). In order to avoid unnecessary copying the server will transfer all passed Transferables which will be emptied on the server side. This should not be a problem in general as IPFS node itself does not retain references to returned values, but is something to keep in mind when doing something custom.

License

Licensed under either of

Contribute

Contributions welcome! Please check out the issues.

Also see our contributing document for more information on how we work, and about contributing in general.

Please be aware that all interactions related to this repo are subject to the IPFS Code of Conduct.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Keywords

ipfs

FAQs

Package last updated on 25 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts