connect.io
Advanced tools
Comparing version 0.5.4 to 0.5.5
import EventEmitter from 'events'; | ||
import uuid from './uuid'; | ||
import noop from './noop'; | ||
function noop() {} | ||
export default class Port extends EventEmitter { | ||
@@ -7,0 +6,0 @@ |
import EventEmitter from 'events'; | ||
import Port from './port'; | ||
import noop from './noop'; | ||
@@ -12,13 +13,24 @@ const {runtime} = window.chrome || { runtime : false }; | ||
// 第一次调用 new Server() 的时候才添加这些监听 | ||
let initListener; | ||
if ( runtime ) { | ||
runtime.onConnect.addListener( chromePort => { | ||
initServerPort( chromePort , false ); | ||
} ); | ||
initListener = ()=> { | ||
initListener = noop; | ||
const {onConnect,onConnectExternal} = runtime; | ||
let {onConnectExternal} = runtime; | ||
if ( onConnectExternal ) { | ||
onConnectExternal.addListener( chromePort => { | ||
initServerPort( chromePort , true ); | ||
} ); | ||
} | ||
if ( onConnect ) { | ||
onConnect.addListener( chromePort => { | ||
initServerPort( chromePort , false ); | ||
} ); | ||
} | ||
if ( onConnectExternal ) { | ||
onConnectExternal.addListener( chromePort => { | ||
initServerPort( chromePort , true ); | ||
} ); | ||
} | ||
}; | ||
} else { | ||
initListener = noop; | ||
} | ||
@@ -77,2 +89,3 @@ /** | ||
constructor( namespace = 'default' ) { | ||
initListener(); | ||
super(); // super() 必须被第一个执行,否则会出错 | ||
@@ -79,0 +92,0 @@ |
{ | ||
"name": "connect.io", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"description": "chrome.runtime.connect wrapper that using Stock.IO API.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
200552
11
2615