Skip to content

Commit ba7a723

Browse files
Gourav DwivediGourav Dwivedi
authored andcommitted
class and method renaming for documentation
1 parent 9df6d6e commit ba7a723

File tree

17 files changed

+10643
-144
lines changed

17 files changed

+10643
-144
lines changed

ChromeExtension/abc.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
function init() {
2+
console.log('App launch');
3+
4+
var url = document.getElementById('server-url').value;
5+
var port = document.getElementById('server-port').value;
6+
7+
debugger;
8+
startWebserver(url, port, 'SR', null);
9+
10+
11+
12+
function startWebserverDirectoryEntry(host,port,entry) {
13+
directoryServer = new WSC.WebApplication({host:host,
14+
port:port,
15+
renderIndex:true,
16+
entry:entry
17+
})
18+
directoryServer.start()
19+
}
20+
21+
//directory must be a subdirectory of the package
22+
function startWebserver(host,port,directory,settings){
23+
chrome.runtime.getPackageDirectoryEntry(function(packageDirectory){
24+
25+
console.log('packageDirectory - ' + packageDirectory);
26+
var data1 = packageDirectory.getDirectory(directory,{create: false},function(webroot){
27+
28+
console.log('webroot - ' + webroot);
29+
debugger;
30+
31+
var fs = new WSC.FileSystem(webroot)
32+
var handlers = [['/data.*', AdminDataHandler],
33+
['.*', WSC.DirectoryEntryHandler.bind(null, fs)]]
34+
adminServer = new WSC.WebApplication({host:host,
35+
port:port,
36+
handlers:handlers,
37+
renderIndex:true,
38+
auth:{ username: "a",
39+
password: "a" }
40+
})
41+
adminServer.start()
42+
}, function(e) {
43+
44+
console.log('error g');
45+
console.log(e);
46+
});
47+
48+
});
49+
// console.log('data1');
50+
// console.log(data1);
51+
}
52+
}
53+
54+
window.onload = function () {
55+
debugger;
56+
document.querySelector("#server-start").addEventListener("click", function() {
57+
58+
59+
var url = document.getElementById('server-url').value;
60+
var port = document.getElementById('server-port').value;
61+
62+
var srWcServer = { Url: url, Port: port };
63+
64+
chrome.storage.sync.set({'srWcServerInfo': srWcServer});
65+
chrome.runtime.sendMessage('demo');
66+
67+
// chrome.storage.sync.get(['srWcServerInfo'], function(result) {
68+
// console.log('Value currently is ' + result.srWcServerInfo);
69+
// console.log('Value currently is ' + result);
70+
// });
71+
} );
72+
};

ChromeExtension/index.html

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<!-- <script src="./admin.js"></script> -->
6+
<!-- <script src="./wsc-chrome.js"></script> -->
7+
<script src="./abc.js"></script>
8+
<!-- <script >
9+
10+
11+
12+
function init() {
13+
console.log('App launch');
14+
15+
var url = document.getElementById('server-url').value;
16+
var port = document.getElementById('server-port').value;
17+
18+
debugger;
19+
startWebserver(url, port, 'SR', null);
20+
21+
22+
23+
function startWebserverDirectoryEntry(host,port,entry) {
24+
directoryServer = new WSC.WebApplication({host:host,
25+
port:port,
26+
renderIndex:true,
27+
entry:entry
28+
})
29+
directoryServer.start()
30+
}
31+
32+
//directory must be a subdirectory of the package
33+
function startWebserver(host,port,directory,settings){
34+
chrome.runtime.getPackageDirectoryEntry(function(packageDirectory){
35+
36+
console.log('packageDirectory - ' + packageDirectory);
37+
var data1 = packageDirectory.getDirectory(directory,{create: false},function(webroot){
38+
39+
console.log('webroot - ' + webroot);
40+
debugger;
41+
42+
var fs = new WSC.FileSystem(webroot)
43+
var handlers = [['/data.*', AdminDataHandler],
44+
['.*', WSC.DirectoryEntryHandler.bind(null, fs)]]
45+
adminServer = new WSC.WebApplication({host:host,
46+
port:port,
47+
handlers:handlers,
48+
renderIndex:true,
49+
auth:{ username: "a",
50+
password: "a" }
51+
})
52+
adminServer.start()
53+
}, function(e) {
54+
55+
console.log('error g');
56+
console.log(e);
57+
});
58+
59+
});
60+
// console.log('data1');
61+
// console.log(data1);
62+
}
63+
}
64+
65+
</script> -->
66+
</head>
67+
<body>
68+
<h1>Hello, let's code!</h1>
69+
<div id="setting" >
70+
<div id="setting-form">
71+
<div id="#form-url">
72+
<label for="">Url</label>
73+
<input type="text" id="server-url" value="127.0.0.1">
74+
</div>
75+
<div id="#form-port">
76+
<label for="">Port</label>
77+
<input type="text" id="server-port" value="808">
78+
</div>
79+
<div id="#form-save">
80+
<label for="">Url</label>
81+
<input type="button" id="server-start" value="Start Server">
82+
</div>
83+
</div>
84+
</div>
85+
</body>
86+
</html>

ChromeExtension/test.js

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
1-
chrome.app.runtime.onLaunched.addListener(init);
1+
//chrome.app.runtime.onLaunched.addListener(init);
22

3-
function init() {
3+
chrome.app.runtime.onLaunched.addListener(
4+
function () {
5+
chrome.app.window.create('index.html', {
6+
id: 'main',
7+
bounds: { width: 620, height: 500 }
8+
});
9+
}
10+
);
11+
12+
chrome.runtime.onMessage.addListener(function(request,sender,sendResponse){
13+
if(request == "demo"){
14+
chrome.storage.sync.get(['srWcServerInfo'], function(result) {
15+
console.log('Value currently is ' + result.srWcServerUrl);
16+
console.log('Value currently is ' + result);
17+
18+
debugger;
19+
var url = result.srWcServerInfo.Url;
20+
var port = parseInt(result.srWcServerInfo.Port);
21+
init(url, port)
22+
23+
24+
});
25+
}
26+
});
27+
28+
// chrome.app.window.create('index.html', {
29+
// id: 'main',
30+
// bounds: { width: 620, height: 500 }
31+
// });
32+
33+
function init(url, port) {
434
console.log('App launch');
5-
startWebserver('127.0.0.1', 8085, 'SR', null);
35+
//startWebserver('127.0.0.1', 8085, 'SR', null);
36+
startWebserver(url, port, 'SR', null);
637

738

839

@@ -34,9 +65,21 @@ function init() {
3465
renderIndex:true,
3566
auth:{ username: "a",
3667
password: "a" }
37-
})
38-
adminServer.start()
39-
}, function(e) {
68+
}, function(e) {
69+
console.log('error g2');
70+
console.log(e);
71+
});
72+
73+
try {
74+
adminServer.start()
75+
} catch (error) {
76+
console.log('error g2');
77+
console.log(e);
78+
79+
}
80+
81+
82+
}, function(e) {
4083

4184
console.log('error g');
4285
console.log(e);

ChromeExtension/wsc-chrome.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6130,7 +6130,7 @@ WSC.Buffer = Buffer
61306130
var sockets = chrome.sockets
61316131
var _DEBUG = false
61326132

6133-
function WebApplication(opts) {
6133+
function WebApplication(opts, errorCallback) {
61346134
// need to support creating multiple WebApplication...
61356135
if (_DEBUG) {
61366136
console.log('initialize webapp with opts',opts)
@@ -6140,6 +6140,7 @@ WSC.Buffer = Buffer
61406140
this.opts = opts
61416141
this.handlers = opts.handlers || []
61426142
this.init_handlers()
6143+
this.errorCallback = errorCallback;
61436144

61446145
if (opts.retainstr) {
61456146
// special option to setup a handler
@@ -6209,8 +6210,8 @@ WSC.Buffer = Buffer
62096210
if (this.on_status_change) { this.on_status_change() }
62106211
},
62116212
error: function(data) {
6212-
console.error(data)
6213-
this.lasterr = data
6213+
console.error(data);
6214+
this.lasterr = data;
62146215
this.change()
62156216
},
62166217
stop: function(reason) {
@@ -6298,6 +6299,11 @@ WSC.Buffer = Buffer
62986299
} else if (result < 0) {
62996300
this.error({message:'unable to bind to port',
63006301
errno:result})
6302+
if(this.errorCallback)
6303+
{
6304+
this.errorCallback({message:'unable to bind to port', errno:result});
6305+
}
6306+
//throw {message:'unable to bind to port', errno:result};
63016307
} else {
63026308
this.started = true
63036309
var host = this.get_host()

0 commit comments

Comments
 (0)