-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
120 lines (107 loc) · 5.49 KB
/
index.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!doctype html>
<html>
<!--
Dean Rather 2015
MIT Licence
https://github.com/deanrather/Sony-Bravia-Remote/
-->
<head>
<title>Sony Bravia Remote</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<style>
form {text-align: center;}
.form-control {width: 14em;}
button {font-size: 50px !important; width: 70%; height:100%}
p {height: 130px; padding: 10px}
</style>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>Sony Bravia Remote Control</h1>
<form>
<p><label for="IP">TV IP</label><input type="text" class="form-control" id="IP" placeholder="TV IP" value="192.168.0.2"></p>
<p><button type="button" data-code="AAAAAQAAAAEAAAAVAw==" class="btn btn-success">ON</button></p>
<p><button type="button" data-code="AAAAAQAAAAEAAAAvAw==" class="btn btn-danger">OFF</button></p>
<p><button type="button" data-code="AAAAAgAAAHcAAAANAw==" class="btn btn-warning">TV</button></p>
<p><button type="button" data-code="AAAAAQAAAAEAAAAQAw==" class="btn btn-warning">Up</button></p>
<p><button type="button" data-code="AAAAAQAAAAEAAAARAw==" class="btn btn-warning">Down</button></p>
<p><button type="button" data-code="AAAAAgAAABoAAABaAw==" class="btn btn-warning">HDMI1 (BD)</button></p>
<p><button type="button" data-code="AAAAAgAAABoAAABbAw==" class="btn btn-warning">HDMI2 (Nintendo)</button></p>
<p><button type="button" data-code="AAAAAgAAABoAAABcAw==" class="btn btn-warning">HDMI3 (Xbox)</button></p>
<p><button type="button" data-code="AAAAAgAAABoAAABdAw==" class="btn btn-warning">HDMI4 (PC)</button></p>
<p><button type="button" data-code="AAAAAQAAAAEAAAAUAw==" class="btn btn-info">MUTE</button></p>
<p><button type="button" data-code="AAAAAQAAAAEAAAASAw==" class="btn btn-info">VOL UP</button></p>
<p><button type="button" data-code="AAAAAQAAAAEAAAATAw==" class="btn btn-info">VOL DOWN</button></p>
</form>
</div>
</div>
</div>
<script>
window.onload = function () {
$("button").click(function(event) {
var code = $(this).data('code');
var IP = $("#IP").val();
var API = 'http://' + IP + '/IRCC?';
var request_body = buildRequestBody(code);
console.log('code:', code);
console.log('API:', API);
console.log('Request Body:', request_body);
$.ajax
(
{
type: 'POST',
contentType: 'text/plain',
url: API,
headers: {
'X-CERS-DEVICE-ID': 'MediaRemote',
'X-CERS-DEVICE-INFO': 'test'
},
data: request_body,
success: function(rtn){ displayResults(rtn); },
error: function(rtn){ displayResults(rtn); }
}
)
});
displayResults = function(results)
{
console.log(results);
}
buildRequestBody = function(code)
{
return '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:X_SendIRCC xmlns:u="urn:schemas-sony-com:service:IRCC:1"><IRCCCode>' + code + '</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>';
}
/**
* Needs to be done at least once first.
* Doesn't seem to hurt running it several times.
*/
function registerDevice() {
var IP = $("#IP").val();
var API = 'http://' + IP + '/cers/api/register?name=JS%20Remote®istrationType=initial&deviceId=MediaRemote';
$.ajax
(
{
url: API,
success: function(rtn){ displayResults(rtn); },
error: function(rtn){ displayResults(rtn); }
}
)
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)", "i"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$("#IP").val(getParameterByName("IP"));
registerDevice();
}
</script>
</body>
</html>