Skip to content

Commit

Permalink
Add an option to set websocket uri
Browse files Browse the repository at this point in the history
PoC of whiteleaf7#381

* use websocket uri saved in local storage
* add a menu entry to set its value
* default value determined by port/protocol
  • Loading branch information
op8867555 committed Mar 5, 2021
1 parent 59aec08 commit 3ccb76b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/web/public/resources/narou.library.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,17 @@ var Narou = (function() {
},

create_ws_uri: function() {
var uri = storage.get("ws_uri");
if (uri)
return uri;

var host = location.hostname,
port = location.port;
return "ws://" + host + ":" + (parseInt(port) + 1) + "/";
port = location.port || 80,
protocol = (location.protocol === "https:") ? "wss": "ws";
uri = protocol + "://" + host + ":" + (parseInt(port) + 1) + "/";
storage.set("ws_uri", uri);
storage.save();
return uri;
},

onmessage: function(data) {
Expand Down
18 changes: 18 additions & 0 deletions lib/web/public/resources/narou.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,24 @@ Mac スタイル:<br>メニューが画面外にはみ出そうとしたら、
// ページ遷移するだけ
});

/*
* メニュー
* オプション>WebSocket URIを設定する
*/
$("#action-option-ws-uri").on(click_event_name, function(e) {
e.preventDefault();
slideNavbar.slide();
bootbox.prompt({
title: "WebSocket URI:",
value: storage.get("ws_uri"),
callback: function(result) {
if (result) {
storage.set("ws_uri", result);
storage.save();
}
}});
});

/*
* メニュー
* オプション>ヘルプ
Expand Down
5 changes: 5 additions & 0 deletions lib/web/views/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@
%span
%span.glyphicon.glyphicon-wrench
環境設定...
%li#action-option-ws-uri
%a(href="#")
%span
%span.glyphicon.glyphicon-wrench
WebSocketのURIを設定する
%li.divider
%li#action-option-help
%a(href="/help")
Expand Down

0 comments on commit 3ccb76b

Please sign in to comment.