royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlosrov...@apache.org
Subject [royale-asjs] branch develop updated: CompressedRemoteObject to compress the data between client and server optimizing sending times
Date Fri, 18 May 2018 19:22:09 GMT
This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new ea56681  CompressedRemoteObject to compress the data between client and server optimizing
sending times
ea56681 is described below

commit ea56681f2df1e2c157365cfd9f52c884951f463c
Author: Carlos Rovira <carlosrovira@apache.org>
AuthorDate: Fri May 18 21:22:02 2018 +0200

    CompressedRemoteObject to compress the data between client and server optimizing sending
times
---
 .../Network/src/main/resources/basic-manifest.xml  |  1 +
 .../apache/royale/net/CompressedRemoteObject.as    | 73 ++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/frameworks/projects/Network/src/main/resources/basic-manifest.xml b/frameworks/projects/Network/src/main/resources/basic-manifest.xml
index 99d4ad3..6bce39a 100644
--- a/frameworks/projects/Network/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Network/src/main/resources/basic-manifest.xml
@@ -22,6 +22,7 @@
 <componentPackage>
 
     <component id="RemoteObject" class="org.apache.royale.net.RemoteObject"/>
+    <component id="CompressedRemoteObject" class="org.apache.royale.net.CompressedRemoteObject"/>
     <component id="HTTPService" class="org.apache.royale.net.HTTPService"/>
     <component id="BinaryUploader" class="org.apache.royale.net.BinaryUploader"/>
     <component id="CORSCredentialsBead" class="org.apache.royale.net.beads.CORSCredentialsBead"/>
diff --git a/frameworks/projects/Network/src/main/royale/org/apache/royale/net/CompressedRemoteObject.as
b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/CompressedRemoteObject.as
new file mode 100644
index 0000000..363861c
--- /dev/null
+++ b/frameworks/projects/Network/src/main/royale/org/apache/royale/net/CompressedRemoteObject.as
@@ -0,0 +1,73 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.net
+{
+    import org.apache.royale.net.remoting.amf.AMFBinaryData;
+    import org.apache.royale.net.events.ResultEvent;
+
+    COMPILE::SWF
+    {
+        import flash.utils.ByteArray;
+    }
+    
+    /**
+     * A RemoteObject that performs automatic serialization/deserialization of results.
+     *
+     * It deserializes the compressed ByteArray in order to optimize the transfer time.
+     * TOOD improve to serialize the sending.
+     * 
+     */
+    public class CompressedRemoteObject extends RemoteObject
+    {
+        /**
+         * Uses the pako library for the zlib compression algorithm
+         *
+         * <inject_html>
+         * <script src="https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.6/pako.min.js"></script>
+         * </inject_html>
+         */
+        public function CompressedRemoteObject()
+        {
+            super();
+        }
+
+        override public function resultHandler(param:Object):void
+		{
+            COMPILE::JS
+            {
+                // --- Transform the number array into a bytearray
+                var bytearray:Uint8Array = new Uint8Array(param.body);
+
+                // --- uncompress the bytearray to get the real object (tree) and create
the AMFBinaryData with it
+                var data:AMFBinaryData = new AMFBinaryData(window["pako"].inflate(bytearray));
+
+                // --- dispatch the ResultEvent like in the standard RemoteObject with the
inflated result object
+    		    dispatchEvent(new ResultEvent(ResultEvent.RESULT, data.readObject()));
+            }
+
+            COMPILE::SWF
+            {
+                // --- SWF not tested
+                var byteArray:ByteArray = param.body as ByteArray;
+                byteArray.uncompress();
+                dispatchEvent(new ResultEvent(ResultEvent.RESULT, byteArray.readObject()));
+            }
+		}
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
carlosrovira@apache.org.

Mime
View raw message