Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 82c24bc

Browse files
[[ Emscripten Networking ]] Added support for load command to HTML5.
Support for the the load command, similar to that in the mobile engines has been added for HTML5. The code was pretty much all there, it just needed very minor tweaking: A param was missing in the progress callback and the timeout was being set incorrectly, causing most URLs to fail.
1 parent 46dca3b commit 82c24bc

5 files changed

Lines changed: 65 additions & 12 deletions

File tree

docs/dictionary/command/load.lcdoc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Associations: internet library
1212

1313
Introduced: 1.0
1414

15-
OS: mac, windows, linux, ios, android
15+
OS: mac, windows, linux, ios, android, html5
1616

1717
Platforms: desktop, server, mobile
1818

@@ -51,8 +51,12 @@ to it using the <URL> <keyword> as usual. When you request the original
5151
The <callbackMessage> is sent to the <object(glossary)> whose <script>
5252
contains the <load> <command>, after the <URL> is <load|loaded>, so you
5353
can handle the <callbackMessage> to perform any tasks you want to delay
54-
until the URL has been <cache|cached>. Two <parameter|parameters> are
55-
sent with the <message> : the <URL> and the <URLStatus> of the <file>.
54+
until the URL has been <cache|cached>. On iOS, Android and HTML5, four
55+
<parameter|parameters> are sent with the <message> : the <URL>, the
56+
<URLStatus> of the <file>, the contents of the <URL> or an error string
57+
and the total size of the <URL> in bytes. On all other platforms, two
58+
<parameter|parameters> are sent with the <message> : the <URL> and the
59+
<URLStatus> of the <file>.
5660

5761
The <load> <command> is non-blocking, so it does not stop the current
5862
<handler> while the <download> is completed. The <handler> continues
@@ -83,18 +87,22 @@ remove it from the <cache>.
8387
> <Standalone Application Settings> window, make sure the "Internet"
8488
> script library is selected.
8589

86-
>*Cross-platform note:* On iOS and Android, the <load> <command>
90+
>*Cross-platform note:* On iOS, Android and HTML5, the <load> <command>
8791
> is implemented in the engine. Therefore the <Internet library> is not
88-
> needed to ensure the <command> works in a mobile
89-
> <standalone application>. If included, the <Internet library>
90-
> implementation will be used instead of the engine implementation.
92+
> needed to ensure the <command> works in a <standalone application>. If
93+
> included, the <Internet library> implementation will be used instead of
94+
> the engine implementation.
9195

9296
> *Note:* When specifying URLs for iOS or Android, you must use the
9397
> appropriate form that conforms to [RFC
9498
> 1738](https://tools.ietf.org/html/rfc1738). Ensure that you
9599
> <URLEncode> any username and password fields appropriately for FTP
96100
> URLs.
97101

102+
> *Note:* The HTML5 engine only supports HTTP and HTTPs protocols.
103+
> Also, only URLs from the domain hosting the web page running the HTML5
104+
> engine can be fetched.
105+
98106
References: unload (command), libURLftpUpload (command),
99107
libURLDownloadToFile (command), get (command), load (command),
100108
group (command), function (control structure),

docs/dictionary/message/urlProgress.lcdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Sent when updates on ongoing url requests are communicated.
99

1010
Introduced: 4.6.1
1111

12-
OS: ios, android
12+
OS: ios, android, html5
1313

14-
Platforms: mobile
14+
Platforms: mobile, desktop
1515

1616
Example:
1717
on urlProgress pUrl, pStatus

docs/guides/HTML5 Deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ The HTML5 engine in this release of LiveCode has a limited range of features. Y
3131
* read and write temporary files in a special virtual filesystem (which is erased when the user navigates away from the page)
3232
* use LiveCode Builder widgets and extensions
3333
* interact with JavaScript code in the web page using `do <script> as "JavaScript"`
34+
* perform basic networking operations using the **load** command
3435

3536
Several important features are not yet supported:
3637

3738
* some `ask` and `answer` message boxes
3839
* multimedia (the "player" control)
39-
* networking
4040
* JavaScript in LiveCode Builder extensions
4141

4242
Two important unsupported features are unlikely to be added in the near future:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# HTML5 Basic Networking Support
2+
3+
Basic networking support has been added to the HTML5 engine by way of the **load** command. The HTML5 **load** command functions in the same way as the **load** command on mobile platforms, with a completion message being sent on download, containing the contents of the URL (or any error) and the **urlProgress** message being sent periodically during the request.
4+
5+
**Note - this functionality is only temporary, with extended libURL style syntax coming soon.**
6+
7+
**Note - only HTTP and HTTPS protocols are supported and URLs can only be fetched from the domain hosting the web page running the HTML5 engine.**
8+
9+
```
10+
command fetchURL pURL
11+
load URL pURL with "loadComplete"
12+
end fetchURL
13+
14+
on loadComplete pURL, pStatus, pData, pTotal
15+
-- pURL - The URL being fetched.
16+
--
17+
-- pStatus - The status of the URL: One of:
18+
-- * downloaded
19+
-- * error
20+
--
21+
-- pData - This will be:
22+
-- * the content of the URL, if pStatus is downloaded
23+
-- * the error string, if pStatus is error
24+
--
25+
-- pTotal - The total size of the URL, in bytes.
26+
end loadComplete
27+
28+
on urlProgress pURL, pStatus, pData, pTotal
29+
-- pURL - The URL being fetched.
30+
--
31+
-- pStatus - The current status of the operation. One of:
32+
-- * contacted
33+
-- * requested
34+
-- * loading
35+
-- * downloaded
36+
-- * error
37+
--
38+
-- pData - This will be:
39+
-- * the number of bytes fetched, if pStatus is loading
40+
-- * the error string, if pStatus is error
41+
-- * empty in all other cases
42+
--
43+
-- pTotal - The total size of the URL, in bytes.
44+
end urlProgress
45+
```

engine/src/em-url.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mergeInto(LibraryManager.library, {
5151
'number', // int32_t p_total_length
5252
'number', // MCSystemUrlCallback p_callback
5353
'number'], // void *p_context
54-
[loadedLength, callbackPtr, contextPtr]);
54+
[loadedLength, totalLength, callbackPtr, contextPtr]);
5555
},
5656

5757
_postStatusFinished: function(data, callbackPtr, contextPtr) {
@@ -201,7 +201,7 @@ mergeInto(LibraryManager.library, {
201201
}
202202

203203
// Timeout
204-
xhr.timeout = timeout;
204+
xhr.timeout = timeout * 1000;
205205

206206
// We want an array buffer response (no string decoding
207207
// etc.)

0 commit comments

Comments
 (0)