Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Making it so that you can select a network interface in the webserver

  • Loading branch information...
commit a75a6d28c97550a11e54d3ac91d5d310ca188668 1 parent 111ee14
@PaulKinlan PaulKinlan authored
Showing with 20 additions and 2 deletions.
  1. +7 −0 webserver/index.html
  2. +13 −2 webserver/index.js
View
7 webserver/index.html
@@ -53,6 +53,10 @@
height: 100px;
overflow-y: auto;
}
+
+ select {
+ display: block;
+ }
</style>
</head>
<body>
@@ -61,6 +65,9 @@
<p>Serving you locally</p>
<p>
<input type="file" webkitdirectory id="directory"/><br />
+ <select id="hosts">
+ <option value="127.0.0.1">lo - 127.0.0.1</option>
+ </select>
<button id="start" class="btn btn-primary btn-large" disabled>Start</button>
<button id="stop" class="btn btn-warning btn-large" disabled>Stop</button>
</p>
View
15 webserver/index.js
@@ -1,6 +1,7 @@
onload = function() {
var start = document.getElementById("start");
var stop = document.getElementById("stop");
+ var hosts = document.getElementById("hosts");
var directory = document.getElementById("directory");
var socket = chrome.experimental.socket || chrome.socket;
@@ -120,7 +121,7 @@ onload = function() {
start.onclick = function() {
socket.create("tcp", {}, function(_socketInfo) {
socketInfo = _socketInfo;
- socket.listen(socketInfo.socketId, "127.0.0.1", 8080, 20, function(result) {
+ socket.listen(socketInfo.socketId, hosts.value, 8080, 20, function(result) {
console.log("LISTENING:", result);
socket.accept(socketInfo.socketId, onAccept);
});
@@ -134,7 +135,17 @@ onload = function() {
stop.onclick = function() {
directory.disabled = false;
stop.disabled = true;
-
+ start.disabled = false;
socket.destroy(socketInfo.socketId);
};
+
+ socket.getNetworkList(function(interfaces) {
+ for(var i in interfaces) {
+ var interface = interfaces[i];
+ var opt = document.createElement("option");
+ opt.value = interface.address;
+ opt.innerText = interface.name + " - " + interface.address;
+ hosts.appendChild(opt);
+ }
+ });
};
Please sign in to comment.
Something went wrong with that request. Please try again.