mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
commit a prototype client for websocket protocol (able to send and show messages from socket only)
This commit is contained in:
6
.gitattributes
vendored
6
.gitattributes
vendored
@@ -13503,6 +13503,12 @@ src/main/config/forge.ico -text svneol=unset#image/ico
|
|||||||
src/main/config/forge.sh svneol=native#text/x-sh
|
src/main/config/forge.sh svneol=native#text/x-sh
|
||||||
src/main/config/forge_checks.xml svneol=native#text/xml
|
src/main/config/forge_checks.xml svneol=native#text/xml
|
||||||
src/main/config/support/template.applescript -text
|
src/main/config/support/template.applescript -text
|
||||||
|
src/main/html/css/core.css -text
|
||||||
|
src/main/html/index.html -text
|
||||||
|
src/main/html/js/jquery/jquery-1.9.1.js -text
|
||||||
|
src/main/html/js/jquery/jquery-1.9.1.min.js -text
|
||||||
|
src/main/html/js/main.js -text
|
||||||
|
src/main/html/js/websocket.js -text
|
||||||
src/main/java/forge/Action.java -text
|
src/main/java/forge/Action.java -text
|
||||||
src/main/java/forge/Card.java svneol=native#text/plain
|
src/main/java/forge/Card.java svneol=native#text/plain
|
||||||
src/main/java/forge/CardCharacteristicName.java -text
|
src/main/java/forge/CardCharacteristicName.java -text
|
||||||
|
|||||||
22
src/main/html/css/core.css
Normal file
22
src/main/html/css/core.css
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
ul, ol { margin: 0; }
|
||||||
|
|
||||||
|
div { border: 0px solid black; }
|
||||||
|
div.wrap { width: 640px; margin: 100px auto;}
|
||||||
|
|
||||||
|
.title { height: 24px; background-color: #ddd; padding: 4px; border: 1px solid black; border-bottom: 0px }
|
||||||
|
.title input {width: 300px; }
|
||||||
|
.title span { display: inline-block; width: 120px; text-align: right; }
|
||||||
|
|
||||||
|
.messages { height: 20ex; overflow: auto; background-color: #eee; padding: 4px; border: 1px solid black; list-style: none; }
|
||||||
|
.messages .incoming { color: #006; }
|
||||||
|
.messages .incoming:before { content: "<< "}
|
||||||
|
.messages .outcoming { color: #060; }
|
||||||
|
.messages .outcoming:before { content: ">> "}
|
||||||
|
.messages .error { color: #600; }
|
||||||
|
|
||||||
|
.packets { padding: 4px; background-color: #ddd; border: 1px solid black; border-top: 0px; display: none; }
|
||||||
|
.packets span { display: inline-block; width: 120px; text-align: right; }
|
||||||
|
.packets input {width: 400px; }
|
||||||
|
.packets button { width: 100px; }
|
||||||
|
|
||||||
|
span.alert { font-style: italic; }
|
||||||
30
src/main/html/index.html
Normal file
30
src/main/html/index.html
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Tail-based by Web Sockets</title>
|
||||||
|
|
||||||
|
|
||||||
|
<link href="css/core.css" media="all" rel="stylesheet" type="text/css" />
|
||||||
|
<script type="text/javascript" src="js/jquery/jquery-1.9.1.min.js"></script>
|
||||||
|
<script type="text/javascript" src="js/websocket.js"></script>
|
||||||
|
<script type='text/javascript' src="js/main.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="wrap">
|
||||||
|
<div class="title">
|
||||||
|
<span>Your server: <b>ws://</b></span>
|
||||||
|
<input id="ws_uri" type="text" value="localhost:81/" name="uri"/>
|
||||||
|
<button id="connect" name="connect" class="cn">Connect</button>
|
||||||
|
<button id="disconn" name="disconn" class="dc" disabled="disabled">Disconnect</button>
|
||||||
|
</div>
|
||||||
|
<ul class="messages" id='messages'></ul>
|
||||||
|
<div class="packets" id='input'>
|
||||||
|
<span>Raw text to send:</span>
|
||||||
|
<input type="text" name="packet" value="" />
|
||||||
|
<button id="send" class="send">Send</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
9597
src/main/html/js/jquery/jquery-1.9.1.js
vendored
Normal file
9597
src/main/html/js/jquery/jquery-1.9.1.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5
src/main/html/js/jquery/jquery-1.9.1.min.js
vendored
Normal file
5
src/main/html/js/jquery/jquery-1.9.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
67
src/main/html/js/main.js
Normal file
67
src/main/html/js/main.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
if (!window.WebSocket)
|
||||||
|
alert("WebSocket not supported by this browser");
|
||||||
|
|
||||||
|
var server = new CWebSocket();
|
||||||
|
var listener = {
|
||||||
|
onOpen : function() {
|
||||||
|
server.send('websockets are open for communications!');
|
||||||
|
$('#input').fadeIn();
|
||||||
|
},
|
||||||
|
|
||||||
|
onMessage : function(m) {
|
||||||
|
if (m.data) {
|
||||||
|
$('#messages').append(makeLi("incoming", m.data));
|
||||||
|
var messageBox = $('#messages')[0];
|
||||||
|
messageBox.scrollTop = messageBox.scrollHeight - messageBox.clientHeight;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onClose : function(m) {
|
||||||
|
$('#messages').append(makeLi("error", "Connection was closed (" + m.code + "): " + m.reason));
|
||||||
|
onDisconnectClicked();
|
||||||
|
$('#input').fadeOut();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
server.addListener(listener);
|
||||||
|
|
||||||
|
function makeLi(className, text) {
|
||||||
|
var spanText = document.createElement('li');
|
||||||
|
spanText.className = className;
|
||||||
|
spanText.innerHTML = text;
|
||||||
|
return spanText;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onConnectClicked() {
|
||||||
|
server.connect($("#ws_uri").val());
|
||||||
|
$('#connect').attr("disabled", "disabled")
|
||||||
|
$('#disconn').removeAttr("disabled")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDisconnectClicked() {
|
||||||
|
server.close();
|
||||||
|
$('#disconn').attr("disabled", "disabled")
|
||||||
|
$('#connect').removeAttr("disabled")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSendClicked() {
|
||||||
|
var toSend = $("#input input").val();
|
||||||
|
$("#input input").val("");
|
||||||
|
$('#messages').append(makeLi("outcoming", toSend));
|
||||||
|
server.send(toSend)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInputKey(event) {
|
||||||
|
if( event.keyCode == 13 )
|
||||||
|
onSendClicked();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onReady() {
|
||||||
|
$('#connect').on("click", onConnectClicked);
|
||||||
|
$('#disconn').on("click", onDisconnectClicked);
|
||||||
|
$('#send').on("click", onSendClicked);
|
||||||
|
$("#input input").on("keypress", onInputKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(onReady)
|
||||||
51
src/main/html/js/websocket.js
Normal file
51
src/main/html/js/websocket.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// There should be some kind of fallback to Flash-powered sockets (IE 9-, Opera with sockets switched off)
|
||||||
|
var CWebSocket = function() {
|
||||||
|
var _t = this;
|
||||||
|
var eventListeners = {};
|
||||||
|
var eventNames = ["Open", "Message", "Close", "Error"];
|
||||||
|
var ws;
|
||||||
|
|
||||||
|
function onOpen() { callListener.apply("Open", arguments); }
|
||||||
|
function onClose() { callListener.apply("Close", arguments); }
|
||||||
|
function onError() { callListener.apply("Error", arguments); }
|
||||||
|
function onMessage() { callListener.apply("Message", arguments); }
|
||||||
|
|
||||||
|
function callListener() {
|
||||||
|
var q = eventListeners[this]
|
||||||
|
if ( q ) for( var i = 0; i < q.length; i++ ) q[i]['on'+ this].apply(q[i], arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
_t.connect = function(location) {
|
||||||
|
ws = new WebSocket("ws://" + location);
|
||||||
|
ws.onopen = onOpen;
|
||||||
|
ws.onmessage = onMessage;
|
||||||
|
ws.onclose = onClose;
|
||||||
|
ws.onerror = onError;
|
||||||
|
}
|
||||||
|
|
||||||
|
_t.addListener = function(obj) {
|
||||||
|
for(var i = 0; i < eventNames.length; i++) {
|
||||||
|
var evName = eventNames[i]
|
||||||
|
var method = obj["on" + evName];
|
||||||
|
if( typeof(method) === 'function') {
|
||||||
|
var handlers = eventListeners[evName]
|
||||||
|
if( 'undefined' === typeof(handler))
|
||||||
|
handlers = eventListeners[evName] = [];
|
||||||
|
handlers.push(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_t.getWs = function() { return ws; }
|
||||||
|
_t.isOpen = function() { return ws && ws.readyState == ws.OPEN; }
|
||||||
|
_t.close = function() { ws && ws.close(); }
|
||||||
|
|
||||||
|
|
||||||
|
function _send(message) {
|
||||||
|
ws && ws.send(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
_t.send = function(text) {
|
||||||
|
text != null && text.length > 0 && _send(text);
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user