-
Notifications
You must be signed in to change notification settings - Fork 1
/
base.html
78 lines (71 loc) · 2.86 KB
/
base.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<html>
<head>
<title>Turntable.fm API Direct Connection</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<style>
html,body{margin:0;background: #e6e6e6;}
#log {width:440px; height:200px; border:1px solid #7F9DB9; overflow:auto;}
#msg {width:330px;}
.container{box-shadow: 0px 1px 6px #999;background:white;padding:20px;}
</style>
</head>
<body onload="init()"><div class="container">
<h3>Turntable.fm API Direct Connection</h3>
<div id="log"></div>
<div><b>Raw request:</b></div>
<input id="msg" type="textbox" onkeypress="onkey(event)"/>
<button onclick="send()">Send</button>
<button onclick="quit()">Quit</button>
<div><b>Config:</b> (does not save yet!)</div>
USERAUTH: <input id="userauth" type="textbox" onkeypress="onkey(event)"/><br>
USERID: <input id="userid" type="textbox" onkeypress="onkey(event)"/><br>
ROOMID: <input id="roomid" type="textbox" onkeypress="onkey(event)"/><br>
<div><b>Quick commands:</b></div>
<button onclick="try{ socket.send({usr}); log('Sent: '+msg); } catch(ex){ log(ex); }">presence.update (online)</button><br>
<button onclick="send.user.authenticate()">user.authenticate</button><br>
<button onclick="send.user.modify.chrome()">user.modify (chrome laptop)</button><br>
<input id="room.speak.msg" type="textbox" onkeypress="onkey(event)"/> <button onclick="send.room.speak()">room.speak</button><br>
<script>
if (window.MozWebSocket) {window.WebSocket = window.MozWebSocket;}
var socket;
function init(){
var host = "ws://chat5.turntable.fm:80/socket.io/websocket";
try{
socket = new WebSocket(host);
log('Init - status '+socket.readyState);
socket.onopen = function(msg){ log("Connected - status "+this.readyState); };
socket.onmessage = function(msg){ log("Received: "+msg.data); };
socket.onclose = function(msg){ log("Disconnected - status "+this.readyState); };
}
catch(ex){ log(ex); }
$("msg").focus();
}
function send(){
var txt,msg;
txt = $("msg");
msg = txt.value;
if(!msg){ alert("Message can not be empty"); return; }
txt.value="";
txt.focus();
try{ socket.send(msg); log('Sent: '+msg); } catch(ex){ log(ex); }
}
function quit(){
log("Connection closed!");
socket.close();
socket=null;
}
// Utilities
function $(id){ return document.getElementById(id); }
function log(msg){ $("log").innerHTML+="<br>"+msg; }
function onkey(event){ if(event.keyCode==13){ send(); } }
// Quick command functions, in order
function send.presence.update(){
var txt,msg;
txt = $("{"api":"presence.update","status":"available","msgid":2,"userid":"'+userid+'","userauth":"'+userauth+'"};");
msg = txt.value;
if(!msg){ alert("Something is empty"); return; }
try{ socket.send(msg); log('Sent: '+msg); } catch(ex){ log(ex); }
}
</script>
</div></body>
</html>