Skip to content

Commit e972ff2

Browse files
committed
update 0.4.1 add logging option
1 parent c382fbf commit e972ff2

File tree

8 files changed

+39
-13
lines changed

8 files changed

+39
-13
lines changed

log-full.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// add this file to your "blackbox" e.g. blackboxing, making devtools not show logs as coming from here
22
(function() {
33
if (console.clog) { return }
4-
if (! WSC.DEBUG) {
5-
console.clog = function() {}
6-
return
7-
}
84
var L = {
9-
UPNP: { show: true, color:'green' }
5+
UPNP: { show: true, color:'green' },
6+
WSC: { show: true, color:'green' }
107
}
8+
Object.keys(L).forEach( function(k) { L[k].name = k } )
119
window.ORIGINALCONSOLE = {log:console.log, warn:console.warn, error:console.error}
1210
window.LOGLISTENERS = []
1311
function wrappedlog(method) {
@@ -27,6 +25,7 @@
2725
console.warn = wrappedlog('warn')
2826
console.error = wrappedlog('error')
2927
console.clog = function() {
28+
if (! WSC.DEBUG) { return }
3029
// category specific logging
3130
var tolog = arguments[0]
3231
tolog = L[tolog]

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"short_name": "Web Server",
55
"description": "A Web Server for Chrome, serves web pages from a local folder over the network, using HTTP. Runs offline.",
66
"author": "Kyle Graehl",
7-
"version": "0.4.0",
7+
"version": "0.4.1",
88
"manifest_version": 2,
99
"offline_enabled": true,
1010
"minimum_chrome_version": "45",

package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ rm package.zip
22

33
#zip package.zip -r * -x package.sh -x *.git* -x "*.*~" -x images/cws_*.png -x *.scratch -x polymer-ui/node-modules/**\* -x wsc-chrome.min.js
44

5-
zip package.zip manifest.json *.js *.html images/200*.png polymer-ui/*.html polymer-ui/*.js polymer-ui/*.css -x wsc-chrome.min.js
5+
zip package.zip manifest.json *.js *.html images/200*.png polymer-ui/*.html polymer-ui/*.js polymer-ui/*.css polymer-ui/bower_components/font-roboto/fonts/roboto/Roboto-Bold.ttf -x wsc-chrome.min.js

polymer-ui/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ <h4>Options (needs restart)</h4>
135135
<div>
136136
<paper-checkbox checked="{{optStatic}}" >Plain (static) files view</paper-checkbox>
137137
</div>
138+
<div>
139+
<paper-checkbox checked="{{optVerbose}}" >Verbose logging (navigate to "chrome://inspect", Extensions)</paper-checkbox>
140+
</div>
138141

139142
</template>
140143

polymer-ui/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function settings_ready() {
1717
//window.localOptions = d
1818
console.log('fetched local settings',appOptions)
1919
window.webapp = bg.get_webapp(appOptions.getAll()) // retainStr in here
20+
bg.WSC.VERBOSE = bg.WSC.DEBUG = appOptions.get('optVerbose')
2021
create_polymer_elements()
2122
on_webapp_change()
2223
webapp.on_status_change = on_webapp_change
@@ -162,6 +163,11 @@ function create_polymer_elements() {
162163
observer: 'optIPV6Change',
163164
value: appOptions.options['optIPV6']
164165
},
166+
optVerbose: {
167+
type: Boolean,
168+
observer: 'optVerboseChange',
169+
value: appOptions.options['optVerbose']
170+
},
165171
optCORS: {
166172
type: Boolean,
167173
observer: 'optCORSChange',
@@ -213,6 +219,11 @@ function create_polymer_elements() {
213219
var k = 'optCORS'
214220
this.updateAndSave(k,val)
215221
},
222+
optVerboseChange: function(val) {
223+
var k = 'optVerbose'
224+
this.updateAndSave(k,val)
225+
bg.WSC.VERBOSE = bg.WSC.DEBUG = val
226+
},
216227
optIPV6Change: function(val) {
217228
var k = 'optIPV6'
218229
this.updateAndSave(k,val)

polymer-ui/options.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
type: Boolean,
2323
default: false
2424
},
25+
optVerbose: {
26+
type: Boolean,
27+
default: false
28+
},
2529
optStatic: {
2630
type: Boolean,
2731
default: false

upnp.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
var ipre = iparts.slice(0,i).join('.')
5151
if (ipre == pre) {
5252
match = this.interfaces[j].address
53+
console.clog("UPNP","selected internal address",match)
5354
return match
5455
}
5556
}
@@ -71,9 +72,12 @@
7172
}.bind(this) )
7273
},
7374
onSearchStop: function(info) {
75+
console.clog('UPNP', "search stop")
7476
this.searching = false
75-
this.getIP( function() {
77+
this.getIP( function(gotIP) {
78+
if (! gotIP) { return this.allDone(false) }
7679
this.getMappings( function(mappings) {
80+
if (! mappings) { return this.allDone(false) }
7781
// check if already exists nice mapping we can use.
7882
var internal = this.getInternalAddress()
7983
console.clog('UPNP','got current mappings',mappings,'internal address',internal)
@@ -225,6 +229,8 @@
225229
var info = infos[i]
226230
info.device.runService(info.service,'GetExternalIPAddress',[],oneResult.bind(this, info))
227231
}
232+
} else {
233+
callback(null)
228234
}
229235
}
230236
}
@@ -275,7 +281,7 @@
275281
},
276282
getDescription: function(callback) {
277283
var xhr = new WSC.ChromeSocketXMLHttpRequest
278-
//console.clog('UPNP','query',this.description_url)
284+
console.clog('UPNP','query',this.description_url)
279285
xhr.open("GET",this.description_url)
280286
xhr.setRequestHeader('connection','close')
281287
xhr.responseType = 'xml'
@@ -374,15 +380,15 @@
374380
chrome.sockets.udp.close(parseInt(socketId))
375381
}
376382
this.sockMap = {}
383+
chrome.sockets.udp.onReceive.removeListener( this._onReceive )
384+
chrome.sockets.udp.onReceiveError.removeListener( this._onReceive )
377385
},
378386
stopsearch: function() {
379387
console.clog('UPNP', "stopping ssdp search")
380388
// stop searching, kill all sockets
381389
this.searching = false
382390
this.cleanup()
383391
this.trigger('stop')
384-
chrome.sockets.udp.onReceive.removeListener( this._onReceive )
385-
chrome.sockets.udp.onReceiveError.removeListener( this._onReceive )
386392
},
387393
search: function(opts) {
388394
if (this.searching) { return }

webapp.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
}
169169
},
170170
stop: function(reason, callback) {
171+
this.lasterr = ''
171172
this.urls = []
172173
this.change()
173174
if (callback) { this._stop_callback = callback }
@@ -295,7 +296,8 @@
295296
console.log('listen port ready',info)
296297
this.port = info.port
297298
if (this.opts.optAllInterfaces && this.opts.optDoPortMapping) {
298-
this.upnp = new WSC.UPNP({port:this.port,udp:false,searchtime:1000})
299+
console.clog("WSC","doing port mapping")
300+
this.upnp = new WSC.UPNP({port:this.port,udp:false,searchtime:2000})
299301
this.upnp.reset(this.onPortmapResult.bind(this))
300302
} else {
301303
this.onReady()
@@ -305,7 +307,7 @@
305307
onPortmapResult: function(result) {
306308
var gateway = this.upnp.validGateway
307309
console.log('portmap result',result,gateway)
308-
if (! result.error) {
310+
if (result && ! result.error) {
309311
if (gateway.device && gateway.device.externalIP) {
310312
var extIP = gateway.device.externalIP
311313
this.extra_urls = [{url:'http://'+extIP+':' + this.port}]
@@ -388,6 +390,7 @@
388390
)
389391
},
390392
getInterfaces: function(state, callback) {
393+
console.clog('WSC','no interfaces yet',state)
391394
chrome.system.network.getNetworkInterfaces( function(result) {
392395
console.log('network interfaces',result)
393396
if (result) {

0 commit comments

Comments
 (0)