-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Le Cam
committed
Jun 18, 2019
1 parent
0870d14
commit 57ad79d
Showing
6 changed files
with
181 additions
and
26 deletions.
There are no files selected for viewing
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
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,6 @@ | ||
export { createPeerPublisher, createPeerSubscriber } from './peer' | ||
export { | ||
createPeerContactSubscriber, | ||
readPeerContact, | ||
writePeerContact, | ||
} from './peerContact' |
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,66 @@ | ||
import Bzz, { PollContentOptions } from '@erebos/api-bzz-base' | ||
import { Observable } from 'rxjs' | ||
import { map } from 'rxjs/operators' | ||
|
||
import { PeerContact } from '../schemas/peerContact' | ||
import { | ||
createFeedSubscriber, | ||
readFeedEntity, | ||
writeFeedEntity, | ||
} from '../channels' | ||
import { PEER_CONTACT_NAME } from '../namespace' | ||
|
||
export interface PeerContactParams { | ||
bzz: Bzz<any> | ||
keyPair: any // TODO: keyPair type | ||
peerKey: string | ||
} | ||
|
||
export async function readPeerContact( | ||
params: PeerContactParams, | ||
): Promise<PeerContact | null> { | ||
return await readFeedEntity<PeerContact>({ | ||
bzz: params.bzz, | ||
entityType: PEER_CONTACT_NAME, | ||
keyPair: params.keyPair, | ||
name: PEER_CONTACT_NAME, | ||
writer: params.peerKey, | ||
}) | ||
} | ||
|
||
export async function writePeerContact( | ||
params: PeerContactParams, | ||
data: PeerContact, | ||
): Promise<string> { | ||
return await writeFeedEntity<PeerContact>( | ||
{ | ||
bzz: params.bzz, | ||
entityType: PEER_CONTACT_NAME, | ||
keyPair: params.keyPair, | ||
name: PEER_CONTACT_NAME, | ||
reader: params.peerKey, | ||
}, | ||
data, | ||
) | ||
} | ||
|
||
export interface PeerContactSubscriberParams extends PeerContactParams { | ||
options: PollContentOptions | ||
} | ||
|
||
export function createPeerContactSubscriber( | ||
params: PeerContactSubscriberParams, | ||
): Observable<PeerContact> { | ||
return createFeedSubscriber<PeerContact>({ | ||
bzz: params.bzz, | ||
entityType: PEER_CONTACT_NAME, | ||
keyPair: params.keyPair, | ||
name: PEER_CONTACT_NAME, | ||
options: { | ||
whenEmpty: 'ignore', | ||
...params.options, | ||
mode: 'raw', | ||
}, | ||
writer: params.peerKey, | ||
}).pipe(map((payload: any) => payload.data)) | ||
} |