summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-30 15:11:32 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-30 15:11:32 (GMT)
commita81d48a3beef8b63fd19cc272a6388ad9e21bb4c (patch)
tree712787dcd19c2d2d1b5d4f26feca78f88c37ac87
parentb4165f9269cb71ccb20e9b525c06951e0033ea2b (diff)
reconnecting session works now
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSocket.go26
-rw-r--r--test/socket.html36
2 files changed, 49 insertions, 13 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go
index df58f3f..346dd6a 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSocket.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go
@@ -160,6 +160,23 @@ func (self *webSocketSession) startNewSession(reqdata *webSocketRequestData, con
return http.StatusOK, "SUCCESS"
}
+func (self *webSocketSession) reconnectSession(reqdata *webSocketRequestData, sessions *rhimport.SessionStoreChan) (int, string) {
+ s, code, errstring := sessions.Get(reqdata.UserName, reqdata.Id)
+ if code != http.StatusOK {
+ return code, errstring
+ }
+ self.id = reqdata.Id
+ self.session = s
+ if err := s.AddDoneHandler(self, webSocketDone); err != nil {
+ return http.StatusInternalServerError, err.Error()
+ }
+ if err := s.AddProgressHandler(self, webSocketProgress); err != nil {
+ return http.StatusInternalServerError, err.Error()
+ }
+ s.Run(time.Duration(reqdata.Timeout) * time.Second)
+ return http.StatusOK, "SUCCESS"
+}
+
func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.Conn, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) {
defer ws.Close()
@@ -194,8 +211,13 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.
sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, "This connection already handles a session")
return
}
- sendWebSocketErrorResponse(ws, "", http.StatusNotImplemented, "reconnect session - not yet implemented")
- return
+ code, errstring := session.reconnectSession(&reqdata, sessions)
+ if code != http.StatusOK {
+ sendWebSocketErrorResponse(ws, "", code, errstring)
+ return
+ } else {
+ sendWebSocketResponse(ws, &webSocketResponseData{ResponseCode: code, Type: "ACK", Id: session.id})
+ }
default:
sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command))
return
diff --git a/test/socket.html b/test/socket.html
index ae13e19..0363b20 100644
--- a/test/socket.html
+++ b/test/socket.html
@@ -23,15 +23,21 @@
$('#rawmsg').text("");
this.sock = new WebSocket("ws://localhost:4080/public/socket");
this.sock.onmessage = function (event) {
+ $('#rawmsg').append(event.data);
msg = $.parseJSON(event.data)
- if (msg.TYPE == "ACK") {
- $('#sessionid').val(msg.ID);
+ switch (msg.TYPE) {
+ case "ACK":
+ $('#sessionid').val(msg.ID);
+ $('#buttonrun').attr('disabled','disabled')
+ $('#buttonreconnect').attr('disabled','disabled')
+ $('#buttoncancel').removeAttr('disabled')
+ break;
+ case "DONE":
+ init();
+ break;
}
- $('#rawmsg').append(event.data);
}
this.sock_onopen = function() {
- this.req.COMMAND = "new";
- this.req.TIMEOUT = 200;
this.sock.send(JSON.stringify(this.req));
}
this.sock.onopen = this.sock_onopen.bind(this);
@@ -43,24 +49,31 @@
var s;
function run() {
- req = { LOGIN_NAME: "heslinki",
+ req = { COMMAND: "new",
+ TIMEOUT: 200,
+ LOGIN_NAME: "heslinki",
PASSWORD: "12423",
SHOW_ID: 10002,
CLEAR_SHOW_CARTS: true,
SOURCE_URI: "fake://10000" };
s = new Session(req);
- $('#buttonrun').attr('disabled','disabled')
- $('#buttoncancel').removeAttr('disabled')
+ }
+
+ function reconnect() {
+ req = { COMMAND: "reconnect",
+ LOGIN_NAME: "heslinki",
+ ID: $('#sessionid').val() };
+ s = new Session(req);
}
function cancel() {
s.cancel();
- $('#buttonrun').removeAttr('disabled')
- $('#buttoncancel').attr('disabled','disabled')
}
function init() {
+ $('#sessionid').val("");
$('#buttonrun').removeAttr('disabled')
+ $('#buttonreconnect').removeAttr('disabled')
$('#buttoncancel').attr('disabled','disabled')
}
</script>
@@ -71,7 +84,8 @@
<button id="buttonrun" onclick="run()">start</button>
<button id="buttoncancel" onclick="cancel()">cancel</button>
- <span></span><input id="sessionid" type="text" size="45" label="ID">
+ <input id="sessionid" type="text" size="45" label="ID">
+ <button id="buttonreconnect" onclick="reconnect()">reconnect</button>
<div id="rawmsg" class="data"></div>
</body>
</html>