summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-30 14:21:09 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-30 14:21:09 (GMT)
commit634ccd50a99d1510037cf3f61686e6abebe5a562 (patch)
tree8b355d0135172242bf05dca6eb6f32941c204f0c
parente9a1f32139ea729d0cd57a99132adc837d62690b (diff)
implemented cancel command
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSocket.go6
-rw-r--r--test/socket.html21
2 files changed, 21 insertions, 6 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go
index 1e8cfff..df58f3f 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSocket.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go
@@ -183,6 +183,12 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.
} else {
sendWebSocketResponse(ws, &webSocketResponseData{ResponseCode: code, Type: "ACK", Id: session.id})
}
+ case "cancel":
+ if session.id == "" {
+ sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, "This connection doesn't handle any session")
+ return
+ }
+ session.session.Cancel()
case "reconnect":
if session.id != "" {
sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, "This connection already handles a session")
diff --git a/test/socket.html b/test/socket.html
index e2f7b85..d038527 100644
--- a/test/socket.html
+++ b/test/socket.html
@@ -19,9 +19,10 @@
<script type="text/javascript">
function Session(req) {
this.req = req
+ $('#rawmsg').text("");
this.sock = new WebSocket("ws://localhost:4080/public/socket");
this.sock.onmessage = function (event) {
- $('#rawmsg').text(event.data);
+ $('#rawmsg').append(event.data);
}
this.sock_onopen = function() {
this.req.COMMAND = "new";
@@ -29,25 +30,33 @@
this.sock.send(JSON.stringify(this.req));
}
this.sock.onopen = this.sock_onopen.bind(this);
+ this.cancel = function() {
+ this.sock.send(JSON.stringify({COMMAND: "cancel"}));
+ }
}
var s;
- function init() {
+ function run() {
req = { LOGIN_NAME: "heslinki",
PASSWORD: "12423",
SHOW_ID: 10002,
CLEAR_SHOW_CARTS: true,
- SOURCE_URI: "http://www.tonycuffe.com/mp3/tail%20toddle.mp3" };
+ SOURCE_URI: "fake://10000" };
s = new Session(req);
}
- </script>
+
+ function cancel() {
+ s.cancel();
+ }
+</script>
</head>
- <body onload="init()">
+ <body>
<h1>Radio Helsinki Rivendell Importer:</h1>
+ <button onclick="run()">start</button>
+ <button onclick="cancel()">cancel</button>
<div id="rawmsg" class="data"></div>
-
</body>
</html>