Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vaibhavmuchandi/ipfs-messenger
IPFS helper packager for communication between two ipfs peers using ipfs-pubsub. Ideal for server-to-server communication.
https://github.com/vaibhavmuchandi/ipfs-messenger
Last synced: 11 days ago
JSON representation
IPFS helper packager for communication between two ipfs peers using ipfs-pubsub. Ideal for server-to-server communication.
- Host: GitHub
- URL: https://github.com/vaibhavmuchandi/ipfs-messenger
- Owner: vaibhavmuchandi
- Created: 2022-09-08T11:49:59.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-30T14:32:04.000Z (about 2 years ago)
- Last Synced: 2024-10-07T08:08:20.880Z (about 1 month ago)
- Language: JavaScript
- Size: 126 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ipfs-messenger
> 1-1 messaging for ipfs nodes. Emits connection events, listening for messages, send messages to nodes. Best suited for server-to-server messaging.
## Install
```
npm install @0xvaibhav/ipfs-messenger
```
## Use
Initializing and starting the messenger.
```js
import * as IPFS from "ipfs-core";
import Messenger from "@0xvaibhav/ipfs-messenger";
const ipfs = await IPFS.create();
const messenger = new Messenger(ipfs, {});
await messenger.start();
```
Listen for events emitted when starting messenger.
```js
messenger.on("start", (m) => {
console.log(m.message)
})
```
Once messenger has been started, listen to incoming messages.
```js
messenger.on("message", (m) => {
console.log(m.data)
});
```
Make sure to establish connection with other node before sending any message and only on establishment of connection, proceed to send any message.
```js
messenger.on("connected", (d) => {
console.log(`Connected to ${d.address}`)
messenger.send("to-address", "Any Message (Objects should be stringyfied)")
})
messenger.connect("ipfs-address")
```
Close connection and stop listening for messages.
```js
messenger.on("disconnected", (d) => {
console.log(`Disconnected from ${d.address}`)
})
messenger.on("stop", () => {
console.log("Stopped listening to any incoming messages")
})
messenger.disconnect("ipfs-address")
messenger.stop()
```
#### Find more in the `examples` directory.## API
### new Messenger(ipfs, {options})
* `ipfs` : IPFS Node, Must have pubsub activated.
```js
const messenger = new Messenger(ipfs, {})
```
### messenger.start()
Starts the messenger
### messenger.stop()
Stops the messenger
### messenger.connect(ipfsAddr: string)
* `ipfsAddr`: string, Address of IPFS node to connect with.
Establish connection to IPFS node. Required before sending any message.
### messenger.disconnect(ipfsAddr)
Terminate the connection established with an IPFS node.
### messenger.send(ipfsAddr: string, message: string)
* `message`: string, Data to be sent across.
Send message to the IPFS node with which connection has already been established.
### messenger.events.on("start", ({message}) => console.log(message))
Once the messenger has been started.
### messenger.events.on("stop", ({message}) => console.log(message))
Once the messenger has been stopped.
### messenger.events.on("connected", ({address}) => console.log(address))
When connected with an IPFS node.
### messenger.events.on("disconnected", ({address}) => console.log(address))
When disconnect with an IPFS node.
### messenger.events.on("message", ({data}) => console.log(data))
When a message is received.
### messenger.events.on("sent", ({data}) => console.log(data))
Once a message has been successfully sent.## Contribute
Feel free to join in. All welcome. Open an [issue](https://github.com/vaibhavmuchandi/ipfs-messenger/issues)!