initial commit

master
Thijs de Vries 5 years ago
commit 6dd76d0802

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

@ -0,0 +1,74 @@
# 💻 ws-term
Websockets are made for the web. So what better way to test/develop/debug your websocket than to use a web-app? ws-term is a web-app written in JavaScript. It stores your settings and history locally and you'll never be forced to create an account.
![image-20200115031219391](img/screenshot.png)
## 📖 Quick-guide
1. Download ws-term.html
2. Open it in a text editor and configure a couple settings (L12 - L21)
```javascript
// Address to your websocket. Kind of like an http address
let address = "wss://echo.websocket.org/"
// (array of) ws subprotecol(s) you want to negotiate. false to disable subprotecols
let subProtocol = false
// Retry connection after X ms. Set to false to disable.
let autoReconnect = 1000
// pre-configured history items. You can use these as cheap-ass shortcuts
history.items = []
```
3. Open the HTML file in a browser.
The status will be indicated by the colored tab at the top-left corner.
**Green:**connected
**Red:**disconnected
**Gray:**not yet connected
Terminal messages prefixed by [ws-term] are system messages, and not websocket messages.
## 🚆 Roadmap
**Right now it's pretty barebones:**
- [x] Send and receive websocket messages
- [x] Status indication (connected/disconnected)
- [x] Auto-reconnect support
- [x] Command history (⬆ / ⬇)
- [x] easy configuration (four variables at the top of the document)
- [x] Websocket sub-protocol negotiation support
- [x] A theme I can bear to watch after dark 👀 …
**But there'll be more before the v1.0 release 🏁 :**
- [ ] Port app over to VueJS
- [ ] Provide either terminal tabs, or a t-mux-like interface (or both...)
- [ ] Provide configuration options in the app
- [ ] Store sessions/config locally in an exportable way (LocalStorage?)
- [ ] Session settings like address, port, auto-reconnect time, history and terminal buffer-size. Extendable
- [ ] Session state (previously received/sent messages)
- [ ] Project state (Active terminals, tab order etc)
- [ ] Application state (Active projects)
- [ ] implement PWA to support offline usage
**Maybe in the near future™ **
- Technical socket stats like latency, supported sub-protocols, tls details, bandwidth/rate etc.
- Binary support?.. (blob)
- Frame details
- See and manage ping/pong frames
- Frame type.
- Stats like; corresponding protocol, size, etc
- Further integration for popular sub-protocols like WAMP, XMPP, DRP etc.
- A way to act as proxy. Allow app to use websocket, while maintaining insight in messages/stats. Might be in the form of (Open)SaaS or desktop app.
- Team / collab development features (OpenSaaS)
- …?
## 💚 Help me out
Right now I'm the sole developer, there's no denying that. But you have the power to change this!
Do you have a great idea or improvement? Drop a message in the issue's and I'll try to get you started. Or you can check if there are any existing issues that tickle your fancy.

@ -0,0 +1,151 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="icon" href="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/desktop-computer_1f5a5.png"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
let history = {items:[],position:0}
/////////////// Edit these values //////////////////////////////////////////////////////////
// Address to your websocket. Kind of like an http address //
let address = "wss://echo.websocket.org/" //
// (array of) websocket subprotecol you want to negotiate. false to disable subprotecols //
let subProtocol = false //
// Retry connection after X ms. Set to false to disable. //
let autoReconnect = 1000 //
// pre-configured history items. You can use these as cheap-ass shortcuts //
history.items = [] //
////////////////////////////////////////////////////////////////////////////////////////////
let websocket
history.position = history.items.length
$(function() {
function startSocket() {
$('h1').text(`${address} | ${subProtocol}`)
window.WebSocket = window.WebSocket || window.MozWebSocket;
websocket = (subProtocol == false) ? new WebSocket(address) : new WebSocket(address, subProtocol);
websocket.onopen = function () {
$('div').append(`[ws-term] Connection established.<br>`);
$('h1').css('border-color', 'green');
$("input").prop('disabled', false);
};
websocket.onerror, websocket.onclose = function () {
$('h1').css('border-color', 'red');
$("input").prop('disabled', true);
if(autoReconnect != false) {
$('div').append(`[ws-term] Connection lost. Retrying in ${autoReconnect}ms... <br>`);
setTimeout(() => {
startSocket()
return
},autoReconnect)
return
}
};
websocket.onmessage = function (message) {
console.log(message.data);
$('div').append(`${message.data} <br>`);
$('div').scrollTop($('div')[0].scrollHeight);
};
}
startSocket()
$('button').click(function(e) {
e.preventDefault();
let cmdstring = $('input').val()
$('div').append(`>> ${cmdstring} <br>`);
websocket.send(cmdstring);
if(history.position <= history.items.length || cmdstring != history.items[history.position]) history.items.push(cmdstring)
history.position = history.items.length
$('input').val('');
});
$( "input" ).keydown(function( event ) {
if ( event.which == 38 ) { // up arrow
console.log(history.position)
event.preventDefault();
console.log("up")
if(history.position > 0) {
history.position--
$( "input" ).val(history.items[history.position])
}
}
if ( event.which == 40 ) { // down arrow
event.preventDefault();
console.log("down")
if(history.position < history.items.length) {
history.position++
$( "input" ).val(history.items[history.position])
}
}
});
});
</script>
<style>
* {
font-family: monospace;
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
display: flex;
flex-flow: column;
height: 100vh;
}
h1 {
font-size: 1.2em;
background-color: rgb(32,32,32);
color: rgb(220,220,220);
padding:16px;
margin:0;
border-left: 5px solid #ccc;
transition: border-color 0.5s ease-in-out;
}
div {
border: 1px solid black;
background: #464646;
color: rgb(203,203,203);
flex: 1;
overflow-y: scroll;
padding: 5px;
font-size: 1em;
line-height: 150%;
}
div::-webkit-scrollbar {
display: block;
}
input {
width: 100%;
padding: 12px;
background: #333;
border:0;
border-top: 1px green;
color: rgb(203,203,203);
font-weight: bold;
outline: none;
border-top: 1px solid transparent;
transition: all 0.5s ease-in-out;
}
input:focus {
border-top: 1px solid rgb(29,39,57);
background: #2d2c2c;
}
</style>
</head>
<body>
<h1>WebSockets test</h1>
<div></div>
<form>
<input autofocus type="text" />
<button style="display:none">Send</button>
</form>
</body>
</html>
Loading…
Cancel
Save