summaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
authorPeter Grassberger <petertheone@gmail.com>2016-05-07 00:14:45 (GMT)
committerPeter Grassberger <petertheone@gmail.com>2016-05-07 00:14:45 (GMT)
commit0458e9929d687b571692e78d389ef9ab3f8ef4cd (patch)
tree025ed1620e6a1c4c7127b83eb128ccab1021b6d1 /www
parent8dd1c416db47a8689fb520db8785d109da6719ff (diff)
parent0c0c66adf29b6e3830b67b03a21b77dfb1cbfabf (diff)
Merge branch 'websocket'
Conflicts: www/js/apps.js www/js/auth.js
Diffstat (limited to 'www')
-rw-r--r--www/js/importer.js82
-rw-r--r--www/js/router.js2
2 files changed, 81 insertions, 3 deletions
diff --git a/www/js/importer.js b/www/js/importer.js
index 08a49fb..b34c4b6 100644
--- a/www/js/importer.js
+++ b/www/js/importer.js
@@ -24,10 +24,88 @@
var Rdxport = Rdxport || {};
-Rdxport.Importer = function() {
- this.$el = $('#uploadModal');
+Rdxport.Importer = function(username, token) {
+ this.username = username;
+ this.token = token;
+ this.$el = $('#uploadModal');
this.uploads = [];
+ this.webSocket = null;
+
+ this.initWebSocket();
+};
+
+Rdxport.Importer.CMD_LIST = 'list';
+Rdxport.Importer.CMD_NEW = 'new';
+Rdxport.Importer.CMD_RECONNECT = 'reconnect';
+
+Rdxport.Importer.prototype.initWebSocket = function() {
+ var importer = this;
+
+ var webSocket = new WebSocket('wss://import.helsinki.at/rhimportd');
+
+ webSocket.onclose = function(code, reason) {
+ console.log('close');
+ console.log(code);
+ console.log(reason);
+ };
+
+ webSocket.onerror = function() {
+ console.log('error');
+ };
+
+ webSocket.onopen = function() {
+ console.log('open');
+
+ console.log('send new');
+ var sendOptions = {
+ COMMAND: Rdxport.Importer.CMD_NEW,
+ LOGIN_NAME: importer.username,
+ PASSWORD: importer.token,
+ TIMEOUT: 200,
+ REFERENCE_ID: "999",
+ SHOW_ID: 10000,
+ CLEAR_SHOW_CARTS: true,
+ SOURCE_URI: 'archiv://2016/03/31/05'
+ };
+ console.log(sendOptions);
+ this.send(JSON.stringify(sendOptions));
+ };
+
+ webSocket.onmessage = function(event) {
+ console.log('message');
+ console.log(event.data);
+ };
+
+ /*this.webSocket = new WebSocket('wss://import.helsinki.at/rhimportd');
+
+ this.webSocket.onclose = function(code, reason) {
+ console.log('close');
+ console.log(code);
+ console.log(reason);
+ };
+
+ this.webSocket.onerror = function() {
+ console.log('error');
+ };
+
+ this.webSocket.onopen = function() {
+ console.log('open');
+
+ console.log('send reconnect');
+ var reconnectOptions = {
+ COMMAND: Rdxport.Importer.CMD_RECONNECT,
+ LOGIN_NAME: importer.username,
+ PASSWORD: importer.token
+ };
+ console.log(reconnectOptions);
+ this.send(JSON.stringify(reconnectOptions));
+ };
+
+ this.webSocket.onmessage = function(event) {
+ console.log('message');
+ console.log(event.data);
+ };*/
};
Rdxport.Importer.prototype.resetModal = function() {
diff --git a/www/js/router.js b/www/js/router.js
index d9d070f..cfeaf23 100644
--- a/www/js/router.js
+++ b/www/js/router.js
@@ -52,7 +52,7 @@ Rdxport.Router.prototype.route = function(page, subpage) {
}
if (!importer) {
- importer = new Rdxport.Importer();
+ importer = new Rdxport.Importer(this.auth.username, this.auth.token);
window.onbeforeunload = function(event) {
if (importer.isUploading()) {
return 'Achtung: Es laufen noch imports.';