From d4e8ff188bc82a974fd0a767c2676d4a4b9747b4 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 21 Mar 2017 15:35:01 -0700 Subject: [PATCH] WIP:stream --- library/controllers/index-db-controller.js | 9 ++++----- library/sw-core.js | 15 ++++++++------- package.json | 1 + 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/library/controllers/index-db-controller.js b/library/controllers/index-db-controller.js index 4c53e1094..3373de113 100644 --- a/library/controllers/index-db-controller.js +++ b/library/controllers/index-db-controller.js @@ -5,9 +5,9 @@ module.exports = class IndexDbController extends EventEmitter { super() this.migrations = opts.migrations this.key = opts.key - this.dbObject = opts.global.indexedDB - this.IDBTransaction = opts.global.IDBTransaction || opts.global.webkitIDBTransaction || opts.global.msIDBTransaction || {READ_WRITE: "readwrite"}; // This line should only be needed if it is needed to support the object's constants for older browsers - this.IDBKeyRange = opts.global.IDBKeyRange || opts.global.webkitIDBKeyRange || opts.global.msIDBKeyRange; + this.dbObject = global.indexedDB + this.IDBTransaction = global.IDBTransaction || global.webkitIDBTransaction || global.msIDBTransaction || {READ_WRITE: "readwrite"}; // This line should only be needed if it is needed to support the object's constants for older browsers + this.IDBKeyRange = global.IDBKeyRange || global.webkitIDBKeyRange || global.msIDBKeyRange; this.version = opts.version this.logging = opts.logging this.initialState = opts.initialState @@ -72,8 +72,7 @@ module.exports = class IndexDbController extends EventEmitter { } migrate () { - // Place holder for future migrations eg: - this.db.createObjectStore('dataStore') + this.db.createObjectStore(this.name) } _add (key, objStore, cb = logger) { diff --git a/library/sw-core.js b/library/sw-core.js index 1afcc3cff..41fce637f 100644 --- a/library/sw-core.js +++ b/library/sw-core.js @@ -4,7 +4,9 @@ const urlUtil = require('url') const endOfStream = require('end-of-stream') const asyncQ = require('async-q') const pipe = require('pump') -// const ParentStream = require('iframe-stream').ParentStream + +const SwGlobalListener = require('sw-stream/lib/sw-global-listener.js') +const connectionListener = new SwGlobalListener(self) const setupMultiplex = require('../app/scripts/lib/stream-utils.js').setupMultiplex const PortStream = require('../app/scripts/lib/port-stream.js') // const notification = require('../app/scripts/lib/notifications.js') @@ -148,12 +150,11 @@ function setupController (initState, client) { /* need to write a service worker stream for this */ - var connectionStream //= new ParentStream() - SWGlobal.onmessage = (message) => { - connectRemote(connectionStream, message.origin) - } - - connectRemote(connectionStream, client.origin) + // var connectionStream = new ParentStream() + connectionListener.on('remote', (portStream, messageEvent) => { + debugger + connectRemote(connectionStream, messageEvent.origin) + }) function connectRemote (connectionStream, originDomain) { var isMetaMaskInternalProcess = (originDomain === 'http://localhost:9001') diff --git a/package.json b/package.json index 96d58fa1b..30e89356f 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "request-promise": "^4.1.1", "sandwich-expando": "^1.0.5", "semaphore": "^1.0.5", + "sw-stream": "^1.0.1", "textarea-caret": "^3.0.1", "three.js": "^0.73.2", "through2": "^2.0.1",