-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http and uri classes, mixer::set_hrtf, tts fixes etc
* Finally registered a nice http class reminiscent of bgt's or the curl plugin! It's currently slightly documented. * Register the spec::uri and http_credentials classes. Caused micro cleanup in pocostuff.cpp regarding value constructors. * It is now possible to properly set an hrtf effect on an entire mixer using mixer.set_hrtf and mixer.set_position. * Fix tts_voice.stop() on some platforms, as well as tts_voice.speak_to_file/speak_to_memory on windows. * SConstruct modifications for debug libraries on windows, mostly internal for now. * Very minor work on reactphysics, I think just registered one extra enum. * Fix enet license after replacement with singleheader version.
- Loading branch information
Showing
19 changed files
with
524 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
doc/src/references/builtin/Networking/classes/http/Methods/get.nvgt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
Initiate a get request. | ||
bool get(spec::uri url, name_value_collection@ headers = null, http_credentials@ creds = null); | ||
## Arguments: | ||
* spec::uri url: A valid URI which must have a scheme of either http or https. | ||
* name_value_collection@ headers = null: Pairs of extra http headers to pass on to the server. | ||
* http_credentials@ creds = null: Optional credentials to authenticate the request with. | ||
## Returns: | ||
bool: True if the request was initiated, or false if there was an error. | ||
## Remarks: | ||
Once this method is called and returns true, you will usually want to wait until either http.complete returns true or http.running returns false before thoroughly handling the request. However http.progress, http.status_code, http.response_headers and http.response_body are accessible throughout the request's lifecycle to stream the data or get more detailed information. | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
// Fetch the latest version of NVGT. | ||
http h; | ||
if (!h.get("http://nvgt.gg/downloads/latest_version")) { | ||
alert("oops", "request failed"); // This class will contain more detailed error management facilities in the near future. | ||
return; | ||
} | ||
h.wait(); // You can also use the h.running or h.complete properties in a loop to execute code in the background while the request progresses. | ||
alert("nvgt latest version", h.response_body); | ||
} |
20 changes: 20 additions & 0 deletions
20
doc/src/references/builtin/Networking/classes/http/Methods/reset.nvgt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
Resets the http object to the state it was in at the time of it's construction, canceling any requests in progress. | ||
void reset(); | ||
## Remarks: | ||
This method waits for the current request to cancel successfully, which is usually instant. However from time to time you could see a small delay as the request thread runs to the next point where it can check the cancelation event. | ||
This method is implicitly called whenever the http object destructs. | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
http h; | ||
h.get("https://nvgt.gg"); | ||
wait(20); | ||
h.reset(); | ||
h.get("https://samtupy.com/ip.php"); | ||
h.wait(); | ||
if (h.status_code != 200) alert("oops " + h.status_code, h.response_body); | ||
else alert("IP address displayed after http reset", h.response_body); | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
doc/src/references/builtin/Networking/classes/http/Methods/wait.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# wait | ||
Waits for the current request to complete. | ||
|
||
`void wait();` | ||
|
||
## Remarks: | ||
If no request is in progress, this will return emmedietly. Otherwise, it will block code execution on the calling thread until the request has finished. |
7 changes: 7 additions & 0 deletions
7
doc/src/references/builtin/Networking/classes/http/Properties/progress.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# progress | ||
Determine the percentage of the request download (from 0.0 to 1.0. | ||
|
||
`const float progress;` | ||
|
||
## Remarks: | ||
This property will be 0 if a request is not in progress or if it is not yet in a state where the content length of the download can be known, and -1 if the progress cannot be determined such as if the remote endpoint does not provide a Content-Length header. |
9 changes: 9 additions & 0 deletions
9
doc/src/references/builtin/Networking/classes/http/Properties/response_body.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# response_body | ||
Read and consume any new data from the current request. | ||
|
||
`const string response_body;` | ||
|
||
## Remarks: | ||
It is important to note that accessing this property will flush the buffer stored in the request. This means that for example you do not want to access http.response_body.length(); because the next time http.response_body is accessed it will be empty or might contain new data. | ||
|
||
Proper usage is to continuously append the value of this property to a string or datastream in a loop while h.running is true or h.complete is false. |
37 changes: 37 additions & 0 deletions
37
doc/src/references/builtin/Networking/classes/http/http.nvgt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
Facilitate HTTP requests from a simple, asynchronous interface. | ||
http(); | ||
## Remarks: | ||
This is one of the easiest ways to perform an http request in NVGT without blocking the rest of your code. | ||
Simply create an http object, call either it's get, head or post methods, then begin accessing properties on the object such as progress, status_code or response_body to query and access details of the request. | ||
*/ | ||
|
||
// Example: | ||
#include "size.nvgt" | ||
#include "speech.nvgt" | ||
void main() { | ||
// This script downloads the latest NVGT windows installer and saves it in the current working directory. | ||
http h; | ||
h.get("https://nvgt.zip/windows"); | ||
file f; | ||
string filename = ""; | ||
show_window("downloading..."); | ||
while (!h.complete) { | ||
wait(5); | ||
if (key_pressed(KEY_ESCAPE)) { | ||
f.close(); | ||
file_delete(filename); | ||
return; // Destruction of the http object will cancel any requests in progress. | ||
} | ||
if (!f.active and h.status_code == 200) { // The file is available. | ||
string[]@ path = h.url.get_path_segments(); | ||
filename = path.length() > 0? path[-1] : "http.txt"; | ||
f.open(filename, "wb"); | ||
} | ||
if (f.active) f.write(h.response_body); | ||
if (key_pressed(KEY_SPACE)) speak(round(h.progress * 100, 2) + "%"); | ||
} | ||
int keep = question(filename, size_to_string(f.size) + " downloaded, keep file?"); | ||
f.close(); | ||
if (keep != 1) file_delete(filename); | ||
} |
Oops, something went wrong.