-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: pss send and subscribe * chore: fix linter issues * test: add peer tests with connectivity endpoints * test: change debug url * test: fix linter error * feat: add pss send, receive and subscribe to Bee class * test: add await to pssSend * refactor: change pssReceive to use pssSubscribe * fix: sleep types in test utils * test: changed tests to promise style * fix: leaking handles in tests * test: avoid stuck tests when failing expectations * test: fix empty message issues * docs: add comment to pssReceive * chore: add export to interfaces
- Loading branch information
Showing
10 changed files
with
456 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { safeAxios } from '../../utils/safeAxios' | ||
|
||
export interface NodeAddresses { | ||
overlay: string | ||
underlay: string[] | ||
ethereum: string | ||
public_key: string | ||
pss_public_key: string | ||
} | ||
|
||
export async function getNodeAddresses(url: string): Promise<NodeAddresses> { | ||
const response = await safeAxios<NodeAddresses>({ | ||
url: url + '/addresses', | ||
responseType: 'json', | ||
}) | ||
|
||
return response.data | ||
} | ||
|
||
export interface Peer { | ||
address: string | ||
} | ||
export interface Peers { | ||
peers: Peer[] | ||
} | ||
|
||
export async function getPeers(url: string): Promise<Peers> { | ||
const response = await safeAxios<Peers>({ | ||
url: url + '/peers', | ||
responseType: 'json', | ||
}) | ||
|
||
return response.data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import WebSocket from 'isomorphic-ws' | ||
|
||
import { PublicKey } from '../types' | ||
import { prepareData } from '../utils/data' | ||
import { safeAxios } from '../utils/safeAxios' | ||
|
||
const endpoint = '/pss' | ||
|
||
export interface Response { | ||
message: string | ||
code: number | ||
} | ||
|
||
/** | ||
* Send to recipient or target with Postal Service for Swarm | ||
* | ||
* @param url Bee url | ||
* @param topic Topic name | ||
* @param target Target message address prefix | ||
* @param recipient Recipient public key | ||
* | ||
*/ | ||
export async function send( | ||
url: string, | ||
topic: string, | ||
target: string, | ||
data: string | Uint8Array, | ||
recipient?: PublicKey, | ||
): Promise<Response> { | ||
const response = await safeAxios<Response>({ | ||
method: 'post', | ||
url: `${url}${endpoint}/send/${topic}/${target.slice(0, 4)}`, | ||
data: await prepareData(data), | ||
responseType: 'json', | ||
params: { recipient }, | ||
}) | ||
|
||
return response.data | ||
} | ||
|
||
/** | ||
* Subscribe for messages on the given topic | ||
* | ||
* @param topic Topic name | ||
*/ | ||
export function subscribe(url: string, topic: string): WebSocket { | ||
const wsUrl = url.replace(/^http/i, 'ws') | ||
|
||
return new WebSocket(`${wsUrl}${endpoint}/subscribe/${topic}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.