Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob McElrath committed Mar 2, 2017
1 parent 72949b7 commit 13875e6
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ var Buffer = require('buffer').Buffer
// to the right handlers.
var servers = {}
var sockets = {}

// Thorough check for Chrome App since both Edge and Chrome implement dummy chrome object
if (typeof chrome === 'object' && typeof chrome.runtime === 'object' && typeof chrome.runtime.id === 'string') {
chrome.sockets.tcpServer.onAccept.addListener(onAccept)
chrome.sockets.tcpServer.onAcceptError.addListener(onAcceptError)
chrome.sockets.tcp.onReceive.addListener(onReceive)
chrome.sockets.tcp.onReceiveError.addListener(onReceiveError)
}
var listenersAdded = false

function onAccept (info) {
if (info.socketId in servers) {
Expand Down Expand Up @@ -138,6 +131,17 @@ function Server (options, connectionListener) {
if (!(this instanceof Server)) return new Server(options, connectionListener)
EventEmitter.call(this)

if(!listenersAdded) {
// Thorough check for Chrome App since both Edge and Chrome implement dummy chrome object
if (typeof chrome === 'object' && typeof chrome.runtime === 'object') {
chrome.sockets.tcpServer.onAccept.addListener(onAccept)
chrome.sockets.tcpServer.onAcceptError.addListener(onAcceptError)
chrome.sockets.tcp.onReceive.addListener(onReceive)
chrome.sockets.tcp.onReceiveError.addListener(onReceiveError)
listenersAdded = true
}
}

if (typeof options === 'function') {
connectionListener = options
options = {}
Expand Down Expand Up @@ -516,6 +520,17 @@ inherits(Socket, stream.Duplex)
function Socket (options) {
if (!(this instanceof Socket)) return new Socket(options)

if(!listenersAdded) {
// Thorough check for Chrome App since both Edge and Chrome implement dummy chrome object
if (typeof chrome === 'object' && typeof chrome.runtime === 'object') {
chrome.sockets.tcpServer.onAccept.addListener(onAccept)
chrome.sockets.tcpServer.onAcceptError.addListener(onAcceptError)
chrome.sockets.tcp.onReceive.addListener(onReceive)
chrome.sockets.tcp.onReceiveError.addListener(onReceiveError)
listenersAdded = true
}
}

if (typeof options === 'number') {
options = { fd: options } // Legacy interface.
} else if (options === undefined) {
Expand Down

0 comments on commit 13875e6

Please sign in to comment.