forked from zaheerm/flumotion-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflumotion2stomp.html
450 lines (416 loc) · 18.5 KB
/
flumotion2stomp.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<!doctype html>
<html>
<head>
<script>document.domain=document.domain</script>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.6.custom.css" rel="stylesheet" />
<script type="text/javascript" src="Orbited.js"></script>
<script>
Orbited.settings.port = 8000;
TCPSocket = Orbited.TCPSocket;
</script>
<script type="text/javascript" src="stomp.js"></script>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript" src="jquery.expander.js"></script>
<script type="text/javascript" src="jquery.styledButton.js"></script>
<script type="text/javascript" src="firebugx.js"></script>
<script type="text/javascript">
var POLL_CHANNEL = '/flumotion/poll';
var COMMAND_CHANNEL = '/flumotion/command';
var INITIAL_CHANNEL = '/flumotion/components/initial';
var CHANGES_CHANNEL = '/flumotion/components/changes';
var UISTATE_CHANNEL = '/flumotion/components/uistate';
var OVERALL_MOOD = -1;
var STREAMER_CLIENTS = {};
var stomp = new STOMPClient();
var GREEN = "#0f0";
var RED = "#f00";
var YELLOW = "#ff0";
var ORANGE = "#f80";
function initial_receive( msg ) {
console.log('received initial message', msg);
$.each(msg, function(index,value) {
add_component (value);
});
}
function change_overall_mood() {
var mood = "happy";
if ($('div.hungry').length > 0) mood = "hungry";
if ($('div.waking').length > 0) mood = "waking";
if ($('div.sleeping').length > 0) mood = "sleeping";
if ($('div.lost').length > 0) mood = "lost";
if ($('div.sad').length > 0) mood = "sad";
$("#components").attr('class', mood);
}
function get_mood_string(mood) {
var smood = "happy";
if (mood == 0) smood = "happy";
else if (mood == 1) smood = "hungry";
else if (mood == 2) smood = "waking";
else if (mood == 3) smood = "sleeping";
else if (mood == 4) smood = "lost";
else if (mood == 5) smood = "sad";
return smood;
}
function add_component( value ) {
mood = get_mood_string(value["mood"]);
var section = "misc";
if (value["type"].indexOf("http-") != -1) section = "streamers";
else if (value["type"].indexOf("producer") != -1) section = "producers";
else if (value["type"].indexOf("encoder") != -1) section = "encoders";
else if (value["type"].indexOf("muxer") != -1) section = "encoders";
else if (value["type"].indexOf("disk-consumer") != -1) section = "diskers";
else if (value["type"].indexOf("pipeline-converter") != -1) section = "encoders";
var componentname = value["name"].replace(/\./g, "__");
var elementname = "component-" + componentname;
$("#" + section).append('<div id="' + elementname + '" class="unselected component ' + mood + '" onclick="select_component(' + "'" + elementname + "'" +');">' + value["name"] + '</div>');
change_overall_mood();
if (value["messages"].length > 0) {
for(i=0;i<value["messages"].length;i++) {
m = value["messages"][i];
$('#messages').append('<div class="flumotion-message" id="message-' + componentname + '">On component <b>' + value["name"] + "</b>:" + m["text"] + "</div>");
$('#message-' + componentname).expander();
}
}
// do not continue if mood is not happy
if (value["mood"] != 0) return;
else listen_for_stuff(value);
}
function listen_for_stuff(value) {
if (value["type"].indexOf("http-") != -1 || value["type"] == 'disk-consumer') {
var channel_name = UISTATE_CHANNEL + "/" + value["name"];
if (value["type"] == "disk-consumer") channel_name = channel_name + "/filename";
else channel_name = channel_name + "/clients-current";
console.log("subscribing to " + channel_name);
stomp.subscribe(channel_name);
stomp.send(value["name"], POLL_CHANNEL);
}
if (value["type"] == "firewire-producer" || value["type"] == "soundcard-producer" || value["type"] == "audiotest-producer") {
var channel_name = UISTATE_CHANNEL + "/" + value["name"] + '/volume-peak';
stomp.subscribe(channel_name);
stomp.send(value["name"], POLL_CHANNEL);
$('#input').append('<canvas class="volume" id="volumeleft-' + value["name"] + '" width="250" height="30"></canvas><canvas class="volume" id="volumeright-' + value["name"] + '" width="250" height="30"></canvas>')
ctx = document.getElementById('volumeleft-' + value['name']).getContext("2d");
ctx.fillStyle = '#000';
ctx.fillRect(0, 0, 250, 30);
ctx = document.getElementById('volumeright-' + value['name']).getContext("2d");
ctx.fillStyle = '#000';
ctx.fillRect(0, 0, 250, 30);
}
if (value["type"].indexOf("consumer") == -1 && value["type"].indexOf("streamer") == -1) {
var channel_name = UISTATE_CHANNEL + "/" + value["name"] + '/feeders';
stomp.subscribe(channel_name);
stomp.send(value["name"], POLL_CHANNEL);
}
}
function stop_listening_for_stuff(value) {
var componentname = value["name"].replace(/\./g, "__");
if (value["type"].indexOf("http-") != -1 || value["type"] == 'disk-consumer') {
var channel_name = UISTATE_CHANNEL + "/" + value["name"];
if (value["type"] == "disk-consumer") {
channel_name = channel_name + "/filename";
$('#filename-' + componentname).remove();
}
else {
channel_name = channel_name + "/clients-current";
console.log("unsubscribing to " + channel_name);
stomp.unsubscribe(channel_name);
STREAMER_CLIENTS[componentname] = 0;
update_streamer_clients();
}
}
if (value["type"] == "firewire-producer" || value["type"] == "soundcard-producer") {
var channel_name = UISTATE_CHANNEL + "/" + value["name"] + '/volume-peak';
stomp.unsubscribe(channel_name);
$('#volumeleft-' + value["name"]).remove();
$('#volumeright-' + value['name']).remove();
}
if (value["type"].indexOf("consumer") == -1 && value["type"].indexOf("streamer") == -1) {
var channel_name = UISTATE_CHANNEL + "/" + value["name"] + '/feeders';
stomp.unsubscribe(channel_name);
stomp.send(value["name"], POLL_CHANNEL);
}
}
function changes_receive ( msg ) {
console.log('received changes message', msg);
var value = msg["component"]
if (msg["action"] == "disconnected") {
console.log("disconnected from manager")
$('.component').remove();
$('.filename').remove();
STREAMER_CLIENTS = {};
update_streamer_clients();
$('.volume').remove();
$('.flumotion-message').remove();
$("#components").attr('class', "lost");
}
else if (msg["action"] == "connected") {
console.log("connected to manager")
stomp.subscribe(INITIAL_CHANNEL);
}
else if (msg["action"] == "change") {
console.log("change to component " + value["name"]);
var mood = get_mood_string(value["mood"]);
var elementname = "#component-" + value["name"].replace(/\./g, "__");
if (!$(elementname).hasClass(mood)) {
var selected = 1;
if ($(elementname).hasClass('unselected')) selected = 0;
$(elementname).attr("class", mood);
$(elementname).addClass("component");
if (selected) $(elementname).addClass("selected");
else $(elementname).addClass("unselected");
if (value["mood"] > OVERALL_MOOD) change_overall_mood(value["mood"]);
if (value["mood"] == 0) {
console.log(value["name"] + " went happy");
listen_for_stuff(value);
}
else stop_listening_for_stuff(value);
}
}
else if (msg["action"] == "add") {
console.log("new component " + value["name"]);
add_component(value);
}
else if (msg["action"] == "remove") {
console.log("component " + value + " removed");
var componentname = value.replace(/\./g, "__");
var elementname = "#component-" + componentname;
var c = $(elementname);
console.log($(elementname).attr('id') + " being removed");
$(elementname).fadeOut(500, function() { $(elementname).remove(); change_overall_mood(); });
$("#message-" + componentname).remove();
}
}
function uistate_receive(destination, value) {
destsplit = destination.split('/');
var componentname = destsplit[4].replace(/\./g, "__");
if (destsplit[5] == "filename") {
console.log("component " + destsplit[4] + " has changed filename to " + value);
var str = destsplit[4];
if (value == null) str = str + ' is not recording <input id="filenameentry-' + componentname + '" type="text" size="20" /> <span id="startrecord-' + componentname + '">Start Recording</span>';
else str = str + ' is recording to filename ' + value + ' <input id="filenameentry-' + componentname + '" type="text" size="20" /> <span id="startrecord-' + componentname + '">Change Filename</span> <span id="stoprecord-' + componentname + '">Stop Recording</span>';
if ($("#filename-" + componentname).length == 0) {
$("#recordingsummary").append('<div class="filename" id="filename-' + componentname + '">' + str + '</div>');
}
else {
$("#filename-" + componentname).html(str);
}
$('#startrecord-' + componentname).styledButton({'action': function() { start_recording(this); } });
$('#stoprecord-' + componentname).styledButton({'action': function() { stop_recording(this); } });
}
else if (destsplit[5] == 'clients-current') {
STREAMER_CLIENTS[componentname] = parseInt(value);
update_streamer_clients();
console.log("component " + destsplit[4] + " has clients " + value);
}
else if (destsplit[5].indexOf('volume-') != -1) {
draw_volume(destsplit[4], value);
}
else if (destsplit[5] == 'feeders') {
for (var index in value) {
for (var field in value[index]) {
if (field == "clients") {
for (var client in value[index][field]) {
$("#bufferdrop-" + destsplit[4] + "-" + value[index][field][client]["client-id"]).remove();
$("#dropped-buffers").append('<div id="bufferdrop-' + destsplit[4] + "-" + value[index][field][client]["client-id"] + '">Buffers dropped for ' + destsplit[4] + ' -> ' + value[index][field][client]["client-id"] + ' current: ' + value[index][field][client]["buffers-dropped-current"] + ' total: ' + value[index][field][client]["buffers-dropped-total"]);
}
}
}
}
}
}
function start_recording(element) {
var str = element.id;
var params = [];
first_dash = str.indexOf('-');
component = str.slice(first_dash + 1);
filename = $('#filenameentry-' + component).attr('value');
console.log("start recording for component " + component + " with filename " + filename);
if (filename != '') params[0] = filename;
command = { "command" : "componentCallRemote", "method": "changeFilename", "params": params , "component" : component };
stomp.send(JSON.stringify(command), COMMAND_CHANNEL);
}
function stop_recording(element) {
var str = element.id;
first_dash = str.indexOf('-');
component = str.slice(first_dash + 1);
console.log("stop recording for component " + component);
command = { "command" : "componentCallRemote", "method": "stopRecording", "params": [] , "component" : component };
stomp.send(JSON.stringify(command), COMMAND_CHANNEL);
}
function start_all_recordings() {
console.log("start recording for all components");
command = { "command" : "invokeOnComponents", "method": "changeFilename", "params": [] , "component" : "disk-consumer" };
stomp.send(JSON.stringify(command), COMMAND_CHANNEL);
}
function stop_all_recordings() {
console.log("stop recording for all components");
command = { "command" : "invokeOnComponents", "method": "stopRecording", "params": [] , "component" : "disk-consumer" };
stomp.send(JSON.stringify(command), COMMAND_CHANNEL);
}
function iec_scale(db) {
var pct = 0.0
if (db < -70.0) pct = 0.0;
else if (db < -60.0) pct = (db + 70.0) * 0.25;
else if (db < -50.0) pct = (db + 60.0) * 0.5 + 2.5;
else if (db < -40.0) pct = (db + 50.0) * 0.75 + 7.5;
else if (db < -30.0) pct = (db + 40.0) * 1.5 + 15.0;
else if (db < -20.0) pct = (db + 30.0) * 2.0 + 30.0;
else if (db < 0.0) pct = (db + 20.0) * 2.5 + 50.0
else pct = 100.0;
return pct;
}
function draw_volume(component, peaks) {
for(i=0;i<=1;i++) {
var channel = "left";
if (i == 1)
channel = "right";
ctx = document.getElementById('volume' + channel + '-' + component).getContext("2d");
ctx.fillStyle = '#000';
ctx.fillRect(0, 0, 250, 30);
peaklevelpct = iec_scale(peaks[i]);
peakwidth = 250.0 * peaklevelpct/100.0;
orangethreshold = -10.0;
redthreshold = -1.0;
ctx.fillStyle = GREEN;
if (peaks[i] >= orangethreshold) ctx.fillStyle = ORANGE;
if (peaks[i] >= redthreshold) ctx.fillStyle = RED;
if (peakwidth > 0) ctx.fillRect(0, 0, peakwidth, 30);
}
}
function update_streamer_clients() {
var total_clients = 0;
for (i in STREAMER_CLIENTS) {
total_clients = total_clients + STREAMER_CLIENTS[i];
}
$('#listeners').html("Total clients: " + total_clients);
}
function select_component(comp) {
if ($('#' + comp).hasClass("unselected")) {
$('#' + comp).removeClass("unselected").addClass("selected");
}
else {
$('#' + comp).removeClass("selected").addClass("unselected");
}
$('#selectedcomponents').html('Selected components: ');
$.each($('.selected'), function(index, value) { compname = value.childNodes[0].textContent; console.log('component ' + value + " name " + compname); $('#selectedcomponents').append(compname + '<br />'); });
}
function start_selected_components() {
$.each($('.selected'), function(index, value) { compname = value.childNodes[0].textContent; console.log("starting component " + compname); message = { "component": compname, "command": "componentStart"}; stomp.send(JSON.stringify(message), COMMAND_CHANNEL);});
$('.selected').removeClass('selected').addClass('unselected');
console.log("now components unselected");
$('#selectedcomponents').html('Selected components: ');
}
function stop_selected_components() {
$.each($('.selected'), function(index, value) { compname = value.childNodes[0].textContent; console.log("stopping component " + compname); message = { "component": compname, "command": "componentStop"}; stomp.send(JSON.stringify(message), COMMAND_CHANNEL); });
$('.selected').removeClass('selected').addClass('unselected');
console.log("now components unselected");
$('#selectedcomponents').html('Selected components: ');
}
$(document).ready(function() {
// set up stomp client.
stomp.onclose = function(c) { alert('Lost Connection (Please reload), Code: ' + c);};
stomp.onerror = function(error) {
alert("Error (Please reload): " + error);
};
stomp.onerrorframe = function(frame) {
alert("Error (Please reload): " + frame.body);
};
stomp.onconnectedframe = function() {
// Run on initial connection to STOMP (comet) server
stomp.ready = true;
// subscribe to channel CHANNEL = "/ezchat/"
stomp.subscribe(INITIAL_CHANNEL);
};
stomp.onmessageframe = function(frame) {
// Executed when a messge is received
//console.log('frame is', frame);
if (frame.headers["destination"] == "/flumotion/components/initial") {
initial_receive( JSON.parse(frame.body) );
stomp.unsubscribe(INITIAL_CHANNEL);
stomp.subscribe(CHANGES_CHANNEL);
}
else if (frame.headers['destination'] == '/flumotion/components/changes') {
changes_receive ( JSON.parse(frame.body) );
}
else if (frame.headers['destination'].indexOf('/flumotion/components/uistate') != -1) {
uistate_receive(frame.headers['destination'], JSON.parse(frame.body) );
}
};
// Everything is setup. Start the connection!
stomp.connect("localhost", 61613); //, 'guest', 'guest');
$('#startallrecordings').styledButton({'action': function() { start_all_recordings(); } });
$('#stopallrecordings').styledButton({'action': function() { stop_all_recordings(); } });
$('#startcomponent').styledButton({'action': function() { start_selected_components(); } });
$('#stopcomponent').styledButton({'action': function() { stop_selected_components(); } });
$('#components').draggable({ handle: "#selectedcomponents" });
//$('#allcomponents').accordion({fillSpace: true, autoHeight: false, clearStyle: true });
$('#allcomponents').tabs();
$('#allcomponents').resizable();
//{ minHeight: 400, resize: function() { $('#allcomponents').accordion( "resize" ); }});
});
</script>
<style>
#allcomponents {height:500px;}
#allcomponents span {overflow:scroll;}
#summary {position:absolute;left:20px;top:0px;}
#components {position:absolute;right:20px;top:0px;padding:10px;
width:700px;height:700px;
-moz-border-radius:20px;-webkit-border-radius: 20px;
border-radius: 20px; background-color: #EAf0E7;font-size:0.85em;}
#selectedcomponents { cursor: move; }
.happy:before {content:url('images/mood-happy.png')}
.hungry:before {content:url('images/mood-hungry.png')}
.sleeping:before {content:url('images/mood-sleeping.png')}
.sad:before {content:url('images/mood-sad.png')}
.lost:before {content:url('images/mood-lost.png')}
.waking:before {content:url('images/mood-waking.png')}
.unselected {color:black;}
.unselected:hover {cursor:pointer; color: white; background-color:red;}
.selected {color:red;}
.selected:hover {cursor:pointer; color: white; background-color:blue;}
.rounded-corners {-moz-border-radius: 20px; -webkit-border-radius: 20px; border-radius: 20px; background-color: #F0EAE7; }
</style>
<link rel="stylesheet" href="styledButton.css" type="text/css"></link>
</head>
<body>
<div id="summary" class="rounded-corners">
<h2>Summary</h2>
<div id="recordingsummary">
<h3>Recordings</h3>
<span id="startallrecordings">Start/Change All</span> <span id="stopallrecordings">Stop All</span>
</div>
<div id="streamingsummary">
<h3>Streaming</h3>
<div id="listeners"></div>
</div>
<div id="input">
<h3>Input</h3>
</div>
<div id="dropped-buffers">
<h2>Dropped Buffers</h2>
</div>
<div id="messages">
<h2>Messages</h2>
</div>
</div>
<span id="components" class="ui-widget-content">
<div id="selectedcomponents">Selected components:</div><br /><span id="startcomponent">Start</span> <span id="stopcomponent">Stop</span>
<div id="allcomponents">
<ul>
<li><a href="#producers">Producers</a></li>
<li><a href="#encoders">Encoders and Muxers</a></li>
<li><a href="#streamers">Streamers</a></li>
<li><a href="#diskers">Recording</a></li>
<li><a href="#misc">Miscellaneous</a></li>
</ul>
<span id="producers"></span>
<span id="encoders"></span>
<span id="streamers"></span>
<span id="diskers"></span>
<spab id="misc"></span>
</div>
</span>
</body>
</html>