3

我正在尝试在 hyperdb 的两个或多个远程实例之间复制文档

import hyperdb from 'hyperdb'
import signalhub from 'signalhub'
import pump from 'pump'
import swarm from 'webrtc-swarm'
import wrtc from 'electron-webrtc'

let key = Buffer.from(store.key, 'base64')
let db = hyperdb(`./${storage}.db`, key, {
  firstNode: true
})

db.on('ready', () => {
  let uuid = db.local.key.toString('hex')
  console.log('target: ', uuid)
  let channel = db.discoveryKey.toString('hex')
  let hub = signalhub(channel, [ store.swarmHost ])
  let sw = swarm(hub, { wrtc: wrtc(), uuid })
  sw.on('peer', function (peer, uuid) {
    console.log('source: ', uuid)
    // let key = Buffer.from(uuid, 'hex')
    // db.authorize(key, () => {
    let stream = db.replicate(/*{ download: true, upload: true }*/)
    pump(peer, stream, peer, function (err, data) {
      if (err) {
        console.error('error: ', err)
      } else {
        console.log('success: ', data)
      }
    })
    // 
  })
})

我在开发工具中没有发现任何错误,但文档没有传播到 hyperdb 的其他实例

target:  2a69e9bedad2bb4181011966a9003686272393ad...
source:  716a6528ee534dd4165153ad13dfb6bf1f5c2ce5...
success:  undefined
source:  716a6528ee534dd4165153ad13dfb6bf1f5c2ce5...
success:  undefined

无论如何,我在终端中发现了一些错误。

[27700:0402/224705.037:ERROR:adm_helpers.cc(73)] Failed to query stereo recording.
[27700:0402/224707.038:ERROR:peerconnection.cc(5801)] Called in wrong state: kHaveLocalOffer (INVALID_STATE)
[27700:0402/224707.039:ERROR:peerconnection.cc(2233)] Failed to set remote offer sdp: Called in wrong state: kHaveLocalOffer
[27700:0402/224719.415:ERROR:peerconnection.cc(5801)] Called in wrong state: kHaveLocalOffer (INVALID_STATE)
[27700:0402/224719.415:ERROR:peerconnection.cc(2233)] Failed to set remote offer sdp: Called in wrong state: kHaveLocalOffer
[27700:0402/224846.447:ERROR:peerconnection.cc(3011)] AddIceCandidate: ICE candidates can't be added without any remote session description.

一些操作系统和软件包信息。

Operating System - Windows_NT(10.0.17134) - win32/x64
NodeJs - 10.15.1

Global packages
  NPM - 6.4.1
  yarn - 1.13.0
  @quasar/cli - 1.0.0-beta.4
  cordova - 8.1.2 (cordova-lib@8.1.1)

Important local packages
  quasar - 1.0.0-beta.15 -- High performance, Material Design 2, full front end stack with Vue.js -- build SPA, SSR, PWA, Hybrid Mobile Apps and Electron apps, all simultaneously using the same codebase
  @quasar/app - 1.0.0-beta.15 -- Quasar Framework App CLI
  @quasar/extras - 1.1.1 -- Quasar Framework fonts, icons and animations
  vue - 2.6.10 -- Reactive, component-oriented view layer for modern web interfaces.
  vue-router - 3.0.2 -- Official router for Vue.js 2
  vuex - 3.1.0 -- state management for Vue.js
  electron - 4.1.3 -- Build cross platform desktop apps with JavaScript, HTML, and CSS
  electron-packager - Not installed
  electron-builder - 20.39.0 -- A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box
  @babel/core - 7.3.4 -- Babel compiler core.
  webpack - 4.29.6 -- Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
  webpack-dev-server - 3.2.1 -- Serves a webpack app. Updates the browser on changes.
  workbox-webpack-plugin - 4.1.1 -- A plugin for your Webpack build process, helping you generate a manifest of local files that workbox-sw should precache.
  register-service-worker - 1.6.2 -- Script for registering service worker, with hooks
4

0 回答 0