summaryrefslogtreecommitdiff
path: root/WebInterface
diff options
context:
space:
mode:
authornatrixaeria <janng@gmx.de>2019-05-31 14:33:57 +0200
committernatrixaeria <janng@gmx.de>2019-05-31 14:33:57 +0200
commita8908cac9524fabdcf4232c1394a51848f0335af (patch)
tree965cef267f4d0f08d9971d6e0ba1987dfd7f5ee0 /WebInterface
parentb5ec9c693f3abfe36d6d1e4dbf86e084872a4676 (diff)
Create web workers
Diffstat (limited to 'WebInterface')
-rw-r--r--WebInterface/wasm/webhogg/Cargo.toml3
-rwxr-xr-xWebInterface/wasm/webhogg/deploy4
-rwxr-xr-xWebInterface/wasm/webhogg/deploy.py42
-rw-r--r--WebInterface/wasm/webhogg/graphics.js6
-rw-r--r--WebInterface/wasm/webhogg/lighttpd.config7
-rw-r--r--WebInterface/wasm/webhogg/loader.js9
-rw-r--r--WebInterface/wasm/webhogg/mimes1
-rw-r--r--WebInterface/wasm/webhogg/src/lib.rs5
-rw-r--r--WebInterface/wasm/webhogg/webhogg.js8
9 files changed, 72 insertions, 13 deletions
diff --git a/WebInterface/wasm/webhogg/Cargo.toml b/WebInterface/wasm/webhogg/Cargo.toml
index 4342a68..a2e5f8e 100644
--- a/WebInterface/wasm/webhogg/Cargo.toml
+++ b/WebInterface/wasm/webhogg/Cargo.toml
@@ -25,5 +25,6 @@ features = [
'WebGlShader',
'WebGlProgram',
'WebGlBuffer',
- 'Window'
+ 'Window',
+ 'Worker'
]
diff --git a/WebInterface/wasm/webhogg/deploy b/WebInterface/wasm/webhogg/deploy
index 13d1d0a..01bc036 100755
--- a/WebInterface/wasm/webhogg/deploy
+++ b/WebInterface/wasm/webhogg/deploy
@@ -1,2 +1,4 @@
#!/bin/sh
-lighttpd -f ./lighttpd.config
+#killall darkhttpd
+#darkhttpd . --addr 127.0.0.1 --port 8080 --mimetypes mimes
+python3 deploy.py
diff --git a/WebInterface/wasm/webhogg/deploy.py b/WebInterface/wasm/webhogg/deploy.py
new file mode 100755
index 0000000..21d9a5e
--- /dev/null
+++ b/WebInterface/wasm/webhogg/deploy.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+
+from socket import socket, SOL_SOCKET, SO_REUSEADDR
+
+ws = socket()
+ws.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
+ws.bind(('localhost', 8080))
+ws.listen()
+
+class Client:
+ def __init__(self, sock, addr):
+ self.sock, self.addr = sock, addr
+
+ def rec(self):
+ b = b''
+ while not b.endswith(b'\r\n\r\n'):
+ b += self.sock.recv(1)
+ lines = b.replace(b'\r\n', b'\n').decode('utf-8').strip('\n').split('\n')
+ method, loc, ver = lines[0].split(' ')
+ print(f'request from \'{self.addr}\': "{loc}"')
+ attrs = {key: value for key, value in (i.split(': ') for i in lines[1:])}
+ return method, loc, attrs
+
+ def sen(self, loc, ver):
+ f = open(loc, 'rb')
+ c = f.read()
+ f.close()
+ self.sock.send(f'HTTP/1.1 200'.encode('utf-8') + c)
+
+ def run(self):
+ method, loc, attrs = self.rec()
+ self.sen(loc, ver)
+
+
+clients = []
+
+while True:
+ c, a = ws.accept()
+ print(f'{a[0]}:{a[1]} connected')
+ client = Client(c, a)
+ clients.append(clients)
+ client.run()
diff --git a/WebInterface/wasm/webhogg/graphics.js b/WebInterface/wasm/webhogg/graphics.js
new file mode 100644
index 0000000..f3bab19
--- /dev/null
+++ b/WebInterface/wasm/webhogg/graphics.js
@@ -0,0 +1,6 @@
+import {default as init_r} from './webhogg.js'
+import {init_x} from './webhogg.js'
+
+let module = init_r('./pkg/webhogg_bg.wasm');
+
+init_x(module, 'graphics', null);
diff --git a/WebInterface/wasm/webhogg/lighttpd.config b/WebInterface/wasm/webhogg/lighttpd.config
index 406b009..4072b30 100644
--- a/WebInterface/wasm/webhogg/lighttpd.config
+++ b/WebInterface/wasm/webhogg/lighttpd.config
@@ -11,6 +11,8 @@ server.http-parseopts = (
"url-query-20-plus" => "enable"
)
+server.modules += ( "mod_setenv" )
+
server.document-root = "/home/jan/projects/DiscoBot/WebInterface/wasm/webhogg"
server.port = 8080
dir-listing.activate = "enable"
@@ -19,7 +21,7 @@ mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".css" => "text/css",
- ".js" => "application/x-javascript",
+ ".js" => "application/javascript",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".gif" => "image/gif",
@@ -27,3 +29,6 @@ mimetype.assign = (
".wasm" => "application/wasm",
"" => "application/octet-stream"
)
+sentenv.add-response-header = (
+ "Content-Security-Policy" => "worker-src localhost:*"
+)
diff --git a/WebInterface/wasm/webhogg/loader.js b/WebInterface/wasm/webhogg/loader.js
index 50bf69d..cc66ff6 100644
--- a/WebInterface/wasm/webhogg/loader.js
+++ b/WebInterface/wasm/webhogg/loader.js
@@ -1,8 +1,9 @@
import {default as init_r} from './webhogg.js'
import {init_x} from './webhogg.js'
-let m1 = init_r('./pkg/webhogg_bg.wasm');
-let m2 = init_r('./pkg/webhogg_bg.wasm');
+let module = init_r('./pkg/webhogg_bg.wasm');
+
+let graphics = new Worker('./graphics.js')
+
+init_x(module, 'game logic', graphics);
-init_x(m1, 1);
-init_x(m2, 2);
diff --git a/WebInterface/wasm/webhogg/mimes b/WebInterface/wasm/webhogg/mimes
new file mode 100644
index 0000000..007445d
--- /dev/null
+++ b/WebInterface/wasm/webhogg/mimes
@@ -0,0 +1 @@
+application/wasm wasm
diff --git a/WebInterface/wasm/webhogg/src/lib.rs b/WebInterface/wasm/webhogg/src/lib.rs
index 2812ed9..4a79a24 100644
--- a/WebInterface/wasm/webhogg/src/lib.rs
+++ b/WebInterface/wasm/webhogg/src/lib.rs
@@ -6,6 +6,7 @@ mod app;
use wasm_bindgen::prelude::*;
use app::WebhoggApplication as App;
+use web_sys::Worker;
#[macro_use]
extern crate log;
@@ -18,14 +19,14 @@ fn run_application() {
}
#[wasm_bindgen]
-pub fn game_logic_entry() {
+pub fn game_logic_entry(worker: Worker) {
client_logger::init_logger();
info!("game logic initialisation");
}
#[wasm_bindgen]
-pub fn graphics_entry() {
+pub fn graphics_entry(worker: Worker) {
client_logger::init_logger();
info!("graphics initialisation");
diff --git a/WebInterface/wasm/webhogg/webhogg.js b/WebInterface/wasm/webhogg/webhogg.js
index 1011eef..751ac77 100644
--- a/WebInterface/wasm/webhogg/webhogg.js
+++ b/WebInterface/wasm/webhogg/webhogg.js
@@ -50,16 +50,16 @@ __exports.__wbg_error_56a861ecc80f27e1 = __wbg_error_56a861ecc80f27e1
/**
* @returns {void}
*/
-export function game_logic_entry() {
- return wasm.game_logic_entry();
+export function game_logic_entry(worker) {
+ return wasm.game_logic_entry(addHeapObject(worker));
}
__exports.game_logic_entry = game_logic_entry
/**
* @returns {void}
*/
-export function graphics_entry() {
- return wasm.graphics_entry();
+export function graphics_entry(worker) {
+ return wasm.graphics_entry(addHeapObject(worker));
}
__exports.graphics_entry = graphics_entry