Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
feat: expose peer discovery to plugins (#1808)
Browse files Browse the repository at this point in the history
  • Loading branch information
dated authored Mar 10, 2020
1 parent 31d326e commit 8336963
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { create as createPeerAllSandbox } from '@/services/plugin-manager/sandbox/peer-all-sandbox'

class PeerDiscoveryStub {
withLatency () {
return this
}

sortBy () {
return this
}
}

const mockDispatch = jest.fn(() => new PeerDiscoveryStub())

let walletApi
let app
let peerAllSandbox

describe('Peer All Sandbox', () => {
beforeEach(() => {
walletApi = {}
app = {
$store: {
dispatch: mockDispatch
}
}
peerAllSandbox = createPeerAllSandbox(walletApi, app)
peerAllSandbox()
})

it('should expose functions', () => {
expect(mockDispatch).toHaveBeenCalled()
expect(walletApi.peers.all).toBeTruthy()
})
})
1 change: 1 addition & 0 deletions src/renderer/i18n/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ export default {
HTTP: 'Allows performing external web requests',
MENU_ITEMS: 'Allows adding custom menu items to the Desktop Wallet sidebar',
MESSAGING: 'Allows WebFrames access to a one-way messaging system',
PEER_ALL: 'Allows access to the peer discovery',
PEER_CURRENT: 'Allows access to the currently connected peer',
PUBLIC: 'Allows navigation to wallet routes and provides access to the Font Awesome icon set',
PROFILE_ALL: 'Allows access to all available profiles',
Expand Down
1 change: 1 addition & 0 deletions src/renderer/services/plugin-manager/plugin-permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const EVENTS = new Permission({ name: 'EVENTS' })
export const HTTP = new Permission({ name: 'HTTP' })
export const MENU_ITEMS = new Permission({ name: 'MENU_ITEMS' })
export const MESSAGING = new Permission({ name: 'MESSAGING' })
export const PEER_ALL = new Permission({ name: 'PEER_ALL' })
export const PEER_CURRENT = new Permission({ name: 'PEER_CURRENT' })
export const PROFILE_ALL = new Permission({ name: 'PROFILE_ALL' })
export const PROFILE_CURRENT = new Permission({ name: 'PROFILE_CURRENT' })
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/services/plugin-manager/plugin-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TIMERS,
PROFILE_ALL,
PROFILE_CURRENT,
PEER_ALL,
PEER_CURRENT,
STORAGE,
AUDIO,
Expand All @@ -26,6 +27,7 @@ import * as RouteSandbox from './sandbox/route-sandbox'
import * as TimersSandbox from './sandbox/timers-sandbox'
import * as ProfileAllSandbox from './sandbox/profile-all-sandbox'
import * as ProfileCurrentSandbox from './sandbox/profile-current-sandbox'
import * as PeerAllSandbox from './sandbox/peer-all-sandbox'
import * as PeerCurrentSandbox from './sandbox/peer-current-sandbox'
import * as StorageSandbox from './sandbox/storage-sandbox'
import * as AudioSandbox from './sandbox/audio-sandbox'
Expand Down Expand Up @@ -124,6 +126,7 @@ export class PluginSandbox {
[EVENTS.name]: EventsSandbox.create(this.walletApi, this.app),
[HTTP.name]: HttpSandbox.create(this.walletApi, this.plugin),
[MESSAGING.name]: MessagingSandbox.create(this.walletApi, this.app),
[PEER_ALL.name]: PeerAllSandbox.create(this.walletApi, this.app),
[PEER_CURRENT.name]: PeerCurrentSandbox.create(this.walletApi, this.app),
[PROFILE_ALL.name]: ProfileAllSandbox.create(this.walletApi, this.app),
[PROFILE_CURRENT.name]: ProfileCurrentSandbox.create(this.walletApi, this.app),
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/services/plugin-manager/sandbox/peer-all-sandbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function create (walletApi, app) {
return async () => {
if (!walletApi.peers) {
walletApi.peers = {}
}

const peerDiscovery = (await app.$store.dispatch('peer/getPeerDiscovery'))
.withLatency(300)
.sortBy('latency')

walletApi.peers.all = peerDiscovery
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export function create (walletApi, app) {
return () => {
if (!walletApi.peers) {
walletApi.peers = {}
}

walletApi.peers = {
...walletApi.peers,

current: {
get: async (url, options = {}) => {
options.timeout || (options.timeout = 3000)
Expand Down

0 comments on commit 8336963

Please sign in to comment.