OverviewFilesCommitsIssuesDocsReleasesPeers

hypergodot commits / 79bce56

Initial text loading from gateway
79bce5606a37bfa34bf6310522f11c69c6f7c31b
by mauve <ranger@mauve.moe> · 2021-05-25T19:13:21.000Z

Changed files (8) +206 -10

GatewayRequest.gd +36 -0
……@@ -0,0 +1,36 @@
1extends HTTPRequest
2
3signal loaded_data(data)
4signal loading_data(url)
5signal failed_load(url, error)
6
7# Declare member variables here. Examples:
8# var a = 2
9# var b = "text"
10
11
12# Called when the node enters the scene tree for the first time.
13func _ready():
14 pass # Replace with function body.
15
16
17# Called every frame. 'delta' is the elapsed time since the previous frame.
18#func _process(delta):
19# pass
20
21func requestHyper(url):
22 var toload = url.replace("hyper://", "http://127.0.0.1:4973/hyper/")
23 print("Loading " + toload)
24 request(toload)
25 pass
26
27
28func _on_request_completed(result, response_code, headers, body):
29 print("Result", result)
30 print("Response Code", response_code)
31 if response_code != 200:
32 var message = body.get_string_from_utf8()
33 print("Error message:", message)
34 emit_signal("failed_load", result, message)
35 else: emit_signal("loaded_data", body.get_string_from_utf8())
36 pass # Replace with function body.
HyperLoad.tscn +79 -0
……@@ -0,0 +1,79 @@
1[gd_scene load_steps=5 format=2]
2
3[ext_resource path="res://GatewayRequest.gd" type="Script" id=1]
4[ext_resource path="res://Output.gd" type="Script" id=2]
5[ext_resource path="res://StatusLabel.gd" type="Script" id=3]
6[ext_resource path="res://URLBar.gd" type="Script" id=4]
7
8[node name="Control" type="Control"]
9anchor_right = 1.0
10anchor_bottom = 1.0
11__meta__ = {
12"_edit_use_anchors_": false
13}
14
15[node name="Title" type="Label" parent="."]
16margin_left = 210.512
17margin_top = 29.217
18margin_right = 490.512
19margin_bottom = 43.217
20text = "Enter your `hyper://` URL and press `Load`"
21__meta__ = {
22"_edit_use_anchors_": false
23}
24
25[node name="URLBar" type="LineEdit" parent="."]
26margin_left = 16.0
27margin_top = 68.0
28margin_right = 570.0
29margin_bottom = 92.0
30text = "hyper://blog.mauve.moe/"
31script = ExtResource( 4 )
32__meta__ = {
33"_edit_use_anchors_": false
34}
35
36[node name="LoadButton" type="Button" parent="."]
37margin_left = 585.838
38margin_top = 70.4204
39margin_right = 627.838
40margin_bottom = 90.4204
41text = "Load"
42__meta__ = {
43"_edit_use_anchors_": false
44}
45
46[node name="Output" type="Label" parent="."]
47margin_left = 24.0
48margin_top = 109.0
49margin_right = 639.0
50margin_bottom = 623.0
51autowrap = true
52clip_text = true
53script = ExtResource( 2 )
54__meta__ = {
55"_edit_use_anchors_": false
56}
57
58[node name="StatusLabel" type="Label" parent="."]
59margin_left = 33.2978
60margin_top = 636.226
61margin_right = 73.2978
62margin_bottom = 650.226
63text = "Status: Waiting"
64script = ExtResource( 3 )
65__meta__ = {
66"_edit_use_anchors_": false
67}
68
69[node name="HyperLoad" type="HTTPRequest" parent="."]
70script = ExtResource( 1 )
71
72[connection signal="text_entered" from="URLBar" to="URLBar" method="_on_URLBar_text_entered"]
73[connection signal="url" from="URLBar" to="HyperLoad" method="requestHyper"]
74[connection signal="pressed" from="LoadButton" to="URLBar" method="navigate"]
75[connection signal="failed_load" from="HyperLoad" to="StatusLabel" method="setError"]
76[connection signal="loaded_data" from="HyperLoad" to="StatusLabel" method="setLoaded"]
77[connection signal="loaded_data" from="HyperLoad" to="Output" method="setContent"]
78[connection signal="loading_data" from="HyperLoad" to="StatusLabel" method="setLoadingData"]
79[connection signal="request_completed" from="HyperLoad" to="HyperLoad" method="_on_request_completed"]
Output.gd +21 -0
……@@ -0,0 +1,21 @@
1extends Label
2
3
4# Declare member variables here. Examples:
5# var a = 2
6# var b = "text"
7
8
9# Called when the node enters the scene tree for the first time.
10func _ready():
11 pass # Replace with function body.
12
13
14# Called every frame. 'delta' is the elapsed time since the previous frame.
15#func _process(delta):
16# pass
17
18
19func setContent(data):
20 text = data
21 pass # Replace with function body.
README.md +4 -10
……@@ -6,22 +6,16 @@ A Godot plugin and example project for loading assets from the [hypercore-protoc
66
77## Plans:
88
9- Create a node-js based daemon using the `hypercore-fetch` module listening on UNIX domain sockets / Windows named pipes listening on HTTPs
10- Use HTTPClient in GDScript to connect over the unix socket
9- Create a node-js based gateway using the `hypercore-fetch` module listening on http://localhost/
10- Use HTTPClient in GDScript to connect to the gateway
11- Spawn gateway from within Godot in a singleton
1112- Intercept the resource loading code to support `hyper://`?
12- Spawn daemon from within Godot in a singleton
1313
1414## Research:
1515
16### How to communicate over UNIX sockets
17
18- StreamPeer seems to [imply UNIX sockets are supported](https://docs.godotengine.org/en/stable/classes/class_streampeer.html#description)
19- Looks like it isn't actually supported: https://github.com/godotengine/godot/issues/48862
20- Also no support for windows sockets
21- Could implement, or go with something else.
22
2316### How to spawn the daemon
2417
18- [Use pkg](https://www.npmjs.com/package/pkg) to compile [hyper-gateway](https://github.com/RangerMauve/hyper-gateway)
2519- Bundle daemon binaries with the project
2620- Use [OS.execute](https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-execute) with non-blocking mode enabled.
2721- Ensure the process is killed before exiting?
StatusLabel.gd +29 -0
……@@ -0,0 +1,29 @@
1extends Label
2
3
4# Declare member variables here. Examples:
5# var a = 2
6# var b = "text"
7
8
9# Called when the node enters the scene tree for the first time.
10func _ready():
11 pass # Replace with function body.
12
13
14# Called every frame. 'delta' is the elapsed time since the previous frame.
15#func _process(delta):
16# pass
17
18func setLoaded(data):
19 text = "Status: Loaded"
20 pass # Replace with function body.
21
22func setLoading(url):
23 text = "Status: Loading " + url
24 pass # Replace with function body.
25
26
27func setError(url, error):
28 text = "Status: Failed Load" + error
29 pass # Replace with function body.
URLBar.gd +29 -0
……@@ -0,0 +1,29 @@
1extends LineEdit
2
3signal url(url)
4
5# Declare member variables here. Examples:
6# var a = 2
7# var b = "text"
8
9
10# Called when the node enters the scene tree for the first time.
11func _ready():
12 pass # Replace with function body.
13
14
15# Called every frame. 'delta' is the elapsed time since the previous frame.
16#func _process(delta):
17# pass
18
19
20func navigate():
21 var url = text
22 if url.begins_with("hyper://"):
23 emit_signal("url", url)
24 pass # Replace with function body.
25
26
27func _on_URLBar_text_entered(new_text):
28 navigate()
29 pass # Replace with function body.
default_env.tres +2 -0
……@@ -1,5 +1,7 @@
11[gd_resource type="Environment" load_steps=2 format=2]
2
23[sub_resource type="ProceduralSky" id=1]
4
35[resource]
46background_mode = 2
57background_sky = SubResource( 1 )
project.godot +6 -0
……@@ -11,8 +11,14 @@ config_version=4
1111[application]
1212
1313config/name="HyperGodot"
14run/main_scene="res://HyperLoad.tscn"
1415config/icon="res://icon.png"
1516
17[display]
18
19window/size/width=666
20window/size/height=666
21
1622[physics]
1723
1824common/enable_pause_aware_picking=true