add an ipc proxy and integrate with the murmur provider
This commit is contained in:
parent
cd3302aa7e
commit
7b98144c17
|
@ -1,7 +1,6 @@
|
|||
// @flow
|
||||
import React, { PureComponent, Fragment } from 'react';
|
||||
import StatusJS from 'status-js-api';
|
||||
import Murmur from 'murmur-client';
|
||||
import IPFS from 'ipfs';
|
||||
import { isNil } from 'lodash';
|
||||
import Grid from '@material-ui/core/Grid';
|
||||
|
@ -17,13 +16,55 @@ import { openBrowserWindow, addWindowEventListeners } from '../utils/windows';
|
|||
|
||||
const typingNotificationsTimestamp = {};
|
||||
|
||||
import uuid from 'uuid/v4';
|
||||
|
||||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
|
||||
class Provider {
|
||||
|
||||
constructor() {
|
||||
this.notificationCallbacks = [];
|
||||
ipcRenderer.on('rpc-notification', (event, result) => {
|
||||
this.notificationCallbacks.forEach((callback) => {
|
||||
callback(JSON.parse(result));
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
send(payload, callback) {
|
||||
return this.sendAsync(payload, callback);
|
||||
}
|
||||
|
||||
sendAsync(payload, callback) {
|
||||
let id = uuid();
|
||||
ipcRenderer.once('rpc-' + id, (event, response) => {
|
||||
callback(null, JSON.parse(response))
|
||||
});
|
||||
ipcRenderer.send('rpc', id, JSON.stringify(payload));
|
||||
}
|
||||
|
||||
on(type, cb) {
|
||||
if (type !== 'data') return;
|
||||
ipcRenderer.send('rpc-event', type);
|
||||
this.notificationCallbacks.push(cb)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const DEFAULT_CHANNEL = "mytest";
|
||||
const URL = "ws://localhost:8546";
|
||||
const murmur = new Murmur();
|
||||
const status = new StatusJS();
|
||||
|
||||
type Props = {};
|
||||
|
||||
function sendRequest(data, cb) {
|
||||
let id = uuid();
|
||||
ipcRenderer.on('rpc-' + id, (data) => {
|
||||
cb(data);
|
||||
});
|
||||
ipcRenderer.send('rpc', id, data);
|
||||
}
|
||||
|
||||
export default class Home extends PureComponent<Props> {
|
||||
props: Props;
|
||||
|
||||
|
@ -52,9 +93,8 @@ export default class Home extends PureComponent<Props> {
|
|||
connect = async (account) => {
|
||||
if (!account) {
|
||||
this.setState({ loading: true });
|
||||
//status.connect(URL);
|
||||
status.connectToProvider(murmur.provider);
|
||||
murmur.start();
|
||||
let provider = new Provider();
|
||||
status.connectToProvider(provider);
|
||||
return this.onConnect();
|
||||
}
|
||||
|
||||
|
@ -82,10 +122,10 @@ export default class Home extends PureComponent<Props> {
|
|||
}
|
||||
|
||||
pingChannel = (channelName) => {
|
||||
const { currentChannel } = this.state;
|
||||
this.pingInterval = setInterval(() => {
|
||||
status.sendJsonMessage(channelName || currentChannel, {type: "ping"});
|
||||
}, 5 * 1000)
|
||||
// const { currentChannel } = this.state;
|
||||
// this.pingInterval = setInterval(() => {
|
||||
// status.sendJsonMessage(channelName || currentChannel, {type: "ping"});
|
||||
// }, 5 * 1000)
|
||||
}
|
||||
|
||||
setupKeyringController = async (password, mnemonic) => {
|
||||
|
@ -251,6 +291,7 @@ export default class Home extends PureComponent<Props> {
|
|||
}
|
||||
|
||||
typingEvent = () => {
|
||||
return;
|
||||
const { currentChannel } = this.state;
|
||||
const now = (new Date().getTime());
|
||||
|
||||
|
|
|
@ -15,6 +15,12 @@ import { autoUpdater } from 'electron-updater';
|
|||
import path from 'path';
|
||||
import log from 'electron-log';
|
||||
import MenuBuilder from './menu';
|
||||
import Murmur from 'murmur-client';
|
||||
|
||||
const {ipcMain} = require('electron');
|
||||
|
||||
const murmur = new Murmur();
|
||||
murmur.start();
|
||||
|
||||
export default class AppUpdater {
|
||||
constructor() {
|
||||
|
@ -76,6 +82,18 @@ app.on('ready', async () => {
|
|||
icon: path.join(__dirname, 'icons/64x64.png')
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
murmur.provider.on('data', (result) => {
|
||||
mainWindow.send("rpc-notification", JSON.stringify(result));
|
||||
})
|
||||
|
||||
ipcMain.on("rpc", (event, id, payload) => {
|
||||
murmur.provider.sendAsync(JSON.parse(payload), (err, result) => {
|
||||
mainWindow.send("rpc-" + id, JSON.stringify(result));
|
||||
});
|
||||
});
|
||||
}, 2000);
|
||||
|
||||
mainWindow.loadURL(`file://${__dirname}/app.html`);
|
||||
|
||||
// @TODO: Use 'ready-to-show' event
|
||||
|
|
|
@ -271,7 +271,7 @@
|
|||
"ipfs": "^0.33.1",
|
||||
"lodash": "^4.17.11",
|
||||
"memoize-one": "^4.0.3",
|
||||
"murmur-client": "0.0.3",
|
||||
"murmur-client": "^0.1.0",
|
||||
"react": "^16.6.3",
|
||||
"react-dom": "^16.6.3",
|
||||
"react-dropzone": "^7.0.1",
|
||||
|
@ -288,7 +288,8 @@
|
|||
"redux": "^4.0.0",
|
||||
"redux-thunk": "^2.3.0",
|
||||
"source-map-support": "^0.5.6",
|
||||
"status-js-api": "^1.0.9"
|
||||
"status-js-api": "^1.0.9",
|
||||
"uuid": "^3.3.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.x <11",
|
||||
|
|
60
yarn.lock
60
yarn.lock
|
@ -3373,12 +3373,12 @@ caniuse-api@^3.0.0:
|
|||
lodash.uniq "^4.5.0"
|
||||
|
||||
caniuse-db@^1.0.30000889:
|
||||
version "1.0.30000911"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000911.tgz#76262de497a6d914594201eccc10a4d6c5020f98"
|
||||
version "1.0.30000912"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000912.tgz#29c739d8c8fae006de61b51f547bdbf02f5d867e"
|
||||
|
||||
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000844, caniuse-lite@^1.0.30000898, caniuse-lite@^1.0.30000899:
|
||||
version "1.0.30000911"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000911.tgz#5dfb8139ee479722da27000ca92dec47913b9605"
|
||||
version "1.0.30000912"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000912.tgz#08e650d4090a9c0ab06bfd2b46b7d3ad6dcaea28"
|
||||
|
||||
capture-exit@^1.2.0:
|
||||
version "1.2.0"
|
||||
|
@ -7537,6 +7537,10 @@ inquirer@~3.3.0:
|
|||
strip-ansi "^4.0.0"
|
||||
through "^2.3.6"
|
||||
|
||||
int64-buffer@^0.99.1007:
|
||||
version "0.99.1007"
|
||||
resolved "https://registry.yarnpkg.com/int64-buffer/-/int64-buffer-0.99.1007.tgz#211ea089a2fdb960070a2e77cd6d17dc456a5220"
|
||||
|
||||
interface-connection@^0.3.2, interface-connection@~0.3.2:
|
||||
version "0.3.2"
|
||||
resolved "https://registry.yarnpkg.com/interface-connection/-/interface-connection-0.3.2.tgz#e4949883f6ea79fb7edd01ee3f4fca47a29fd2c4"
|
||||
|
@ -8955,6 +8959,10 @@ js-yaml@^3.12.0, js-yaml@^3.7.0, js-yaml@^3.9.0:
|
|||
argparse "^1.0.7"
|
||||
esprima "^4.0.0"
|
||||
|
||||
jsbi@^2.0.4:
|
||||
version "2.0.4"
|
||||
resolved "https://registry.yarnpkg.com/jsbi/-/jsbi-2.0.4.tgz#2bd4709a44d20d34630658142f4846a06e46da5c"
|
||||
|
||||
jsbn@1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-1.1.0.tgz#b01307cb29b618a1ed26ec79e911f803c4da0040"
|
||||
|
@ -9204,9 +9212,9 @@ kleur@^2.0.1:
|
|||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/kleur/-/kleur-2.0.2.tgz#b704f4944d95e255d038f0cb05fb8a602c55a300"
|
||||
|
||||
known-css-properties@^0.9.0:
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.9.0.tgz#28f8a7134cfa3b0aa08b1e5edf64a57f64fc23af"
|
||||
known-css-properties@^0.10.0:
|
||||
version "0.10.0"
|
||||
resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.10.0.tgz#8378a8921e6c815ecc47095744a8900af63d577d"
|
||||
|
||||
last-call-webpack-plugin@^3.0.0:
|
||||
version "3.0.0"
|
||||
|
@ -9705,8 +9713,8 @@ libp2p@~0.23.1:
|
|||
peer-info "~0.14.1"
|
||||
|
||||
linkify-it@^2.0.3:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-2.0.3.tgz#d94a4648f9b1c179d64fa97291268bdb6ce9434f"
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-2.1.0.tgz#c4caf38a6cd7ac2212ef3c7d2bde30a91561f9db"
|
||||
dependencies:
|
||||
uc.micro "^1.0.1"
|
||||
|
||||
|
@ -10686,9 +10694,9 @@ multistream-select@^0.14.1, multistream-select@~0.14.3:
|
|||
semver "^5.5.0"
|
||||
varint "^5.0.0"
|
||||
|
||||
murmur-client@0.0.3:
|
||||
version "0.0.3"
|
||||
resolved "https://registry.yarnpkg.com/murmur-client/-/murmur-client-0.0.3.tgz#fa921da8160f6a9a03ddf2c46b8532bd2b65007f"
|
||||
murmur-client@^0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/murmur-client/-/murmur-client-0.1.0.tgz#572a8550cd574a0198f1ca92af4eafb67c9d86bd"
|
||||
dependencies:
|
||||
big.js "^5.2.2"
|
||||
bigint-buffer "^1.1.2"
|
||||
|
@ -10700,7 +10708,9 @@ murmur-client@0.0.3:
|
|||
ethereumjs-devp2p "^2.5.0"
|
||||
express "^4.16.4"
|
||||
express-ws "^4.0.0"
|
||||
int64-buffer "^0.99.1007"
|
||||
js-sha3 "^0.8.0"
|
||||
jsbi "^2.0.4"
|
||||
lru-cache "^4.1.3"
|
||||
ms "^2.1.1"
|
||||
node-aes-gcm "^0.2.4"
|
||||
|
@ -11928,7 +11938,7 @@ postcss-jsx@^0.35.0:
|
|||
optionalDependencies:
|
||||
postcss-styled ">=0.34.0"
|
||||
|
||||
postcss-less@^3.0.1:
|
||||
postcss-less@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/postcss-less/-/postcss-less-3.1.0.tgz#0e14a80206b452f44d3a09d082fa72645e8168cc"
|
||||
dependencies:
|
||||
|
@ -12665,7 +12675,7 @@ punycode@^1.2.4, punycode@^1.4.1:
|
|||
|
||||
pushdata-bitcoin@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/pushdata-bitcoin/-/pushdata-bitcoin-1.0.1.tgz#15931d3cd967ade52206f523aa7331aef7d43af7"
|
||||
resolved "http://registry.npmjs.org/pushdata-bitcoin/-/pushdata-bitcoin-1.0.1.tgz#15931d3cd967ade52206f523aa7331aef7d43af7"
|
||||
dependencies:
|
||||
bitcoin-ops "^1.3.0"
|
||||
|
||||
|
@ -14470,15 +14480,21 @@ string.prototype.trim@^1.1.2:
|
|||
es-abstract "^1.5.0"
|
||||
function-bind "^1.0.2"
|
||||
|
||||
string_decoder@^1.0.0, string_decoder@^1.1.1, string_decoder@~1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
|
||||
string_decoder@^1.0.0, string_decoder@^1.1.1:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.2.0.tgz#fe86e738b19544afe70469243b2a1ee9240eae8d"
|
||||
dependencies:
|
||||
safe-buffer "~5.1.0"
|
||||
|
||||
string_decoder@~0.10.x:
|
||||
version "0.10.31"
|
||||
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
|
||||
resolved "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
|
||||
|
||||
string_decoder@~1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
|
||||
dependencies:
|
||||
safe-buffer "~5.1.0"
|
||||
|
||||
stringify-entities@^1.0.1:
|
||||
version "1.3.2"
|
||||
|
@ -14583,8 +14599,8 @@ stylelint-config-standard@^18.2.0:
|
|||
stylelint-config-recommended "^2.1.0"
|
||||
|
||||
stylelint@^9.4.0:
|
||||
version "9.8.0"
|
||||
resolved "https://registry.yarnpkg.com/stylelint/-/stylelint-9.8.0.tgz#bfdade6360d82afe820d6b15251b01acf8ffd04d"
|
||||
version "9.9.0"
|
||||
resolved "https://registry.yarnpkg.com/stylelint/-/stylelint-9.9.0.tgz#dde466e9b049e0bd30e912ad280f1a2ecf6efdf8"
|
||||
dependencies:
|
||||
autoprefixer "^9.0.0"
|
||||
balanced-match "^1.0.0"
|
||||
|
@ -14601,7 +14617,7 @@ stylelint@^9.4.0:
|
|||
ignore "^5.0.4"
|
||||
import-lazy "^3.1.0"
|
||||
imurmurhash "^0.1.4"
|
||||
known-css-properties "^0.9.0"
|
||||
known-css-properties "^0.10.0"
|
||||
leven "^2.1.0"
|
||||
lodash "^4.17.4"
|
||||
log-symbols "^2.0.0"
|
||||
|
@ -14613,7 +14629,7 @@ stylelint@^9.4.0:
|
|||
postcss "^7.0.0"
|
||||
postcss-html "^0.34.0"
|
||||
postcss-jsx "^0.35.0"
|
||||
postcss-less "^3.0.1"
|
||||
postcss-less "^3.1.0"
|
||||
postcss-markdown "^0.34.0"
|
||||
postcss-media-query-parser "^0.2.3"
|
||||
postcss-reporter "^6.0.0"
|
||||
|
|
Loading…
Reference in New Issue