Jay Sistar 9 years ago
parent
commit
9b65c5872d

+ 5 - 0
WebRequestChunksExample/JavaScript/Resources.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "07ec626be09169a3981aaff5114d42e4",
+	"FolderImporter": {}
+}

+ 5 - 0
WebRequestChunksExample/JavaScript/Resources/Scripts.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "1bfab9039d648f5bc8bbb5df840214a6",
+	"FolderImporter": {}
+}

+ 32 - 0
WebRequestChunksExample/JavaScript/Resources/Scripts/main.js

@@ -0,0 +1,32 @@
+
+// Non-blocking http request runs asynchronously.
+var request = new Atomic.WebRequest("GET", "https://httpbin.org/get", 0);
+
+// Accumulate the data into this var.
+var data = "";
+
+// Listen for the "download_chunk" event to see when we have data.
+// Note that this event is not available on all platforms.
+request.subscribeToEvent("download_chunk", function (event) {
+
+    data += event.download.readString();
+
+});
+
+// Listen for the "complete" event to see when the response is complete.
+request.subscribeToEvent("complete", function (event) {
+
+    if (event.error) {
+        // When something goes wrong, print the error, then return.
+        console.log("Error:\n" + event.error);
+        return;
+    }
+
+    // We're done, so print the data.
+    console.log("Downloaded:\n" + data);
+
+});
+
+// Nothing happens until send() is called.
+console.log("Sending . . .\n");
+request.send();

+ 7 - 0
WebRequestChunksExample/JavaScript/Resources/Scripts/main.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "67af78bebb9bbcd7f39ffce9f36690e0",
+	"JavascriptImporter": {
+		"IsComponentFile": false
+	}
+}

+ 9 - 0
WebRequestChunksExample/JavaScript/WebRequestChunksExample.atomic

@@ -0,0 +1,9 @@
+{
+   "version": 1,
+   "project": {
+      "version": "1.0.0"
+   },
+   "platforms": [
+      "mac", "windows"
+   ]
+}

+ 1 - 5
WebRequestHeadersExample/JavaScript/Resources/Scripts/main.js

@@ -1,9 +1,6 @@
 
-// Get the web subsystem.
-var web = Atomic.getWeb();
-
 // Non-blocking http request runs asynchronously.
-var request = web.makeWebRequest("GET", "https://httpbin.org/get");
+var request = new Atomic.WebRequest("GET", "https://httpbin.org/get", 0);
 
 // Add some request headers.
 request.setRequestHeader("Some-Special-Header", "Special header value");
@@ -31,4 +28,3 @@ request.subscribeToEvent("complete", function (event) {
 // Nothing happens until send() is called.
 console.log("Sending . . .\n");
 request.send();
-

+ 1 - 5
WebRequestSimpleExample/JavaScript/Resources/Scripts/main.js

@@ -1,9 +1,6 @@
 
-// Get the web subsystem.
-var web = Atomic.getWeb();
-
 // Non-blocking http request runs asynchronously.
-var request = web.makeWebRequest("GET", "https://httpbin.org/get");
+var request = new Atomic.WebRequest("GET", "https://httpbin.org/get", 0);
 
 // Listen for the "complete" event to see when the response is complete.
 request.subscribeToEvent("complete", function (event) {
@@ -22,4 +19,3 @@ request.subscribeToEvent("complete", function (event) {
 // Nothing happens until send() is called.
 console.log("Sending . . .\n");
 request.send();
-

+ 1 - 4
WebSocketExample/JavaScript/Resources/Scripts/main.js

@@ -3,11 +3,8 @@ require('AtomicEventLoop');
 
 var num_times_to_connect = 5;
 
-// Get the web subsystem
-var web = Atomic.getWeb();
-
 // Make the ws:// request
-var ws = web.makeWebSocket("ws://echo.websocket.org");
+var ws = new Atomic.WebSocket("ws://echo.websocket.org");
 
 // Listen for when the websocket is open
 ws.subscribeToEvent("open", function() {