尽管已建立套接字连接,但同步无法正常运行

时间:2018-04-03 12:27:16

标签: couchdb angular5 pouchdb

该项目正在使用11个PouchDB。为了确保同步,在加载/引导Angular 5应用程序时,所有11个DB都被实例化(带同步)。由于同步不起作用(由于浏览器设置的限制),我们转向socket-pouch作为解决方案。我们在所有数据库上禁用了同步,并将套接字同步仅包含在一个数据库中。 socketPouchServer在localhost:5000& CouchDB托管在DigitalOcean上。

在运行系统时, 在浏览器中观察到以下日志。正如你所看到的,"中止"正在记录错误。 https://user-images.githubusercontent.com/26055473/38247973-8eef489a-3764-11e8-8411-6b5b20436d19.png

相同的代码是

import PouchDB from 'pouchdb';
import PouchDBFind from 'pouchdb-find';
import SocketPouchClient from 'socket-pouch/client';

PouchDB.plugin(PouchDBFind);
PouchDB.adapter('socket', SocketPouchClient);
PouchDB.debug.enable('pouchdb:socket:*');

this.dailyMovementDB = new 
PouchDB(`${username}_${environment.REQUIRED_DB_VERSION_NUMBER}_daily-movement`, { auto_compaction: true });
    this.dailyMovementDBRemote = new PouchDB(
    {
        adapter: 'socket',
        name: `${username}_${environment.REQUIRED_DB_VERSION_NUMBER}_daily-movement`,
        url: `${environment.REMOTE_COUCH_DB_BASE_URL}`
    });

    var syncHandler = this.dailyMovementDB.replicate.to(this.dailyMovementDBRemote
    ).on('change', function (change) {
        // yo, something changed!
        console.log('yo, something changed', change);
        instance.autosaveMessageService.syncingProcessEndedSubject.next(false);
    }).on('paused', function (info) {
        console.log('replication was paused, usually because of a lost connection', info);
        // replication was paused, usually because of a lost connection
        instance.autosaveMessageService.syncingProcessEndedSubject.next(true);
    }).on('active', function (info) {
        // replication was resumed
        console.log('replication was resumed', info);
        instance.autosaveMessageService.syncingProcessStartedSubject.next();
    }).on('denied', function (info) {
        // handle complete
        console.log('denied', info);
        instance.autosaveMessageService.syncingProcessEndedSubject.next(false);
    }).on('complete', function (info) {
        // handle complete
        console.log('handle complete', info);
        instance.autosaveMessageService.syncingProcessEndedSubject.next(false);
    }).on('error', function (err) {
        console.log(err);
        // instance.createDailyMovementPouchDBs(username);
        // totally unhandled error (shouldn't happen)
    });

以下日志出现在localhost:5000(socketPouchServer)上 https://user-images.githubusercontent.com/26055473/38248011-ac49b9ca-3764-11e8-8501-74576c8c1e1f.png

以下是socketPouchServer的代码

var socketPouchServer = require('socket-pouch/server');

const PouchDB = require('pouchdb');

socketPouchServer.listen(5000, {
remoteUrl: 'http://remoteurl:5984',
}, () => {
console.log('Hi');
});


Please guide how to resolve this issue.

0 个答案:

没有答案