[spice-html5][PATCH v2 05/13] Expose all needed pieces in main.js

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We don't want the users to rely on anything else than main.js. All the
helper functions from the other files are thus imported in main and
exported there too.

This way all the user needs to import is:

    import * as SpiceHtml5 from './main.js';
---
 main.js         |  9 ++++++++-
 spice.html      | 20 +++++++++-----------
 spice_auto.html | 18 ++++++++----------
 3 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/main.js b/main.js
index 6664207..be73828 100644
--- a/main.js
+++ b/main.js
@@ -24,10 +24,12 @@ import { SpiceCursorConn } from './cursor.js';
 import { SpiceConn } from './spiceconn.js';
 import { DEBUG } from './utils.js';
 import { SpiceFileXferTask } from './filexfer.js';
-import { SpiceInputsConn } from './inputs.js';
+import { SpiceInputsConn, sendCtrlAltDel } from './inputs.js';
 import { SpiceDisplayConn } from './display.js';
 import { SpicePlaybackConn } from './playback.js';
 import { SpicePortConn } from './port.js';
+import { handle_file_dragover, handle_file_drop } from './filexfer.js';
+import { resize_helper, handle_resize } from './resize.js';
 
 /*----------------------------------------------------------------------------
 **  SpiceMainConn
@@ -507,4 +509,9 @@ SpiceMainConn.prototype.relative_now = function()
 
 export {
   SpiceMainConn,
+  handle_file_dragover,
+  handle_file_drop,
+  resize_helper,
+  handle_resize,
+  sendCtrlAltDel,
 };
diff --git a/spice.html b/spice.html
index f55f218..e88348e 100644
--- a/spice.html
+++ b/spice.html
@@ -45,9 +45,7 @@
         </script>
 
         <script type="module" crossorigin="anonymous">
-            import { SpiceMainConn } from './main.js';
-            import { handle_file_dragover, handle_file_drop } from './filexfer.js';
-            import { resize_helper, handle_resize } from './resize.js';
+            import * as SpiceHtml5 from './main.js';
 
             var host = null, port = null;
             var sc;
@@ -82,7 +80,7 @@
 
                 try
                 {
-                    sc = new SpiceMainConn({uri: uri, screen_id: "spice-screen", dump_id: "debug-div",
+                    sc = new SpiceHtml5.SpiceMainConn({uri: uri, screen_id: "spice-screen", dump_id: "debug-div",
                                 message_id: "message-div", password: password, onerror: spice_error, onagent: agent_connected });
                 }
                 catch (e)
@@ -105,26 +103,26 @@
                 {
                     var spice_xfer_area = document.getElementById('spice-xfer-area');
                     document.getElementById('spice-area').removeChild(spice_xfer_area);
-                    document.getElementById('spice-area').removeEventListener('dragover', handle_file_dragover, false);
-                    document.getElementById('spice-area').removeEventListener('drop', handle_file_drop, false);
+                    document.getElementById('spice-area').removeEventListener('dragover', SpiceHtml5.handle_file_dragover, false);
+                    document.getElementById('spice-area').removeEventListener('drop', SpiceHtml5.handle_file_drop, false);
                 }
                 console.log("<< disconnect");
             }
 
             function agent_connected(sc)
             {
-                window.addEventListener('resize', handle_resize);
+                window.addEventListener('resize', SpiceHtml5.handle_resize);
                 window.spice_connection = this;
 
-                resize_helper(this);
+                SpiceHtml5.resize_helper(this);
 
                 if (window.File && window.FileReader && window.FileList && window.Blob)
                 {
                     var spice_xfer_area = document.createElement("div");
                     spice_xfer_area.setAttribute('id', 'spice-xfer-area');
                     document.getElementById('spice-area').appendChild(spice_xfer_area);
-                    document.getElementById('spice-area').addEventListener('dragover', handle_file_dragover, false);
-                    document.getElementById('spice-area').addEventListener('drop', handle_file_drop, false);
+                    document.getElementById('spice-area').addEventListener('dragover', SpiceHtml5.handle_file_dragover, false);
+                    document.getElementById('spice-area').addEventListener('drop', SpiceHtml5.handle_file_drop, false);
                 }
                 else
                 {
@@ -147,7 +145,7 @@
                 }
 
                 window.addEventListener('resize', handle_resize);
-                resize_helper(sc);
+                SpiceHtml5.resize_helper(sc);
             }
             /* SPICE port event listeners
             window.addEventListener('spice-port-data', function(event) {
diff --git a/spice_auto.html b/spice_auto.html
index ad4e171..364d58b 100644
--- a/spice_auto.html
+++ b/spice_auto.html
@@ -45,9 +45,7 @@
         </script>
 
         <script type="module" crossorigin="anonymous">
-            import { SpiceMainConn } from './main.js';
-            import { handle_file_dragover, handle_file_drop } from './filexfer.js';
-            import { resize_helper, handle_resize } from './resize.js';
+            import * as SpiceHtml5 from './main.js';
 
             var host = null, port = null;
             var sc;
@@ -124,7 +122,7 @@
 
                 try
                 {
-                    sc = new SpiceMainConn({uri: uri, screen_id: "spice-screen", dump_id: "debug-div",
+                    sc = new SpiceHtml5.SpiceMainConn({uri: uri, screen_id: "spice-screen", dump_id: "debug-div",
                                 message_id: "message-div", password: password, onerror: spice_error, onagent: agent_connected });
                 }
                 catch (e)
@@ -145,26 +143,26 @@
                 {
                     var spice_xfer_area = document.getElementById('spice-xfer-area');
                     document.getElementById('spice-area').removeChild(spice_xfer_area);
-                    document.getElementById('spice-area').removeEventListener('dragover', handle_file_dragover, false);
-                    document.getElementById('spice-area').removeEventListener('drop', handle_file_drop, false);
+                    document.getElementById('spice-area').removeEventListener('dragover', SpiceHtml5.handle_file_dragover, false);
+                    document.getElementById('spice-area').removeEventListener('drop', SpiceHtml5.handle_file_drop, false);
                 }
                 console.log("<< disconnect");
             }
 
             function agent_connected(sc)
             {
-                window.addEventListener('resize', handle_resize);
+                window.addEventListener('resize', SpiceHtml5.handle_resize);
                 window.spice_connection = this;
 
-                resize_helper(this);
+                SpiceHtml5.resize_helper(this);
 
                 if (window.File && window.FileReader && window.FileList && window.Blob)
                 {
                     var spice_xfer_area = document.createElement("div");
                     spice_xfer_area.setAttribute('id', 'spice-xfer-area');
                     document.getElementById('spice-area').appendChild(spice_xfer_area);
-                    document.getElementById('spice-area').addEventListener('dragover', handle_file_dragover, false);
-                    document.getElementById('spice-area').addEventListener('drop', handle_file_drop, false);
+                    document.getElementById('spice-area').addEventListener('dragover', SpiceHtml5.handle_file_dragover, false);
+                    document.getElementById('spice-area').addEventListener('drop', SpiceHtml5.handle_file_drop, false);
                 }
                 else
                 {
-- 
2.19.2

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]