/usr/share/janus/demos/voicemailtest.js is in janus-demos 0.2.6-1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | // We make use of this 'server' variable to provide the address of the
// REST Janus API. By default, in this example we assume that Janus is
// co-located with the web server hosting the HTML pages but listening
// on a different port (8088, the default for HTTP in Janus), which is
// why we make use of the 'window.location.hostname' base address. Since
// Janus can also do HTTPS, and considering we don't really want to make
// use of HTTP for Janus if your demos are served on HTTPS, we also rely
// on the 'window.location.protocol' prefix to build the variable, in
// particular to also change the port used to contact Janus (8088 for
// HTTP and 8089 for HTTPS, if enabled).
// In case you place Janus behind an Apache frontend (as we did on the
// online demos at http://janus.conf.meetecho.com) you can just use a
// relative path for the variable, e.g.:
//
// var server = "/janus";
//
// which will take care of this on its own.
//
//
// If you want to use the WebSockets frontend to Janus, instead, you'll
// have to pass a different kind of address, e.g.:
//
// var server = "ws://" + window.location.hostname + ":8188";
//
// Of course this assumes that support for WebSockets has been built in
// when compiling the gateway. WebSockets support has not been tested
// as much as the REST API, so handle with care!
//
//
// If you have multiple options available, and want to let the library
// autodetect the best way to contact your gateway (or pool of gateways),
// you can also pass an array of servers, e.g., to provide alternative
// means of access (e.g., try WebSockets first and, if that fails, fall
// back to plain HTTP) or just have failover servers:
//
// var server = [
// "ws://" + window.location.hostname + ":8188",
// "/janus"
// ];
//
// This will tell the library to try connecting to each of the servers
// in the presented order. The first working server will be used for
// the whole session.
//
var server = null;
if(window.location.protocol === 'http:')
server = "http://" + window.location.hostname + ":8088/janus";
else
server = "https://" + window.location.hostname + ":8089/janus";
var janus = null;
var vmailtest = null;
var opaqueId = "voicemailtest-"+Janus.randomString(12);
var started = false;
var spinner = null;
var myusername = null;
var myid = null;
var audioenabled = false;
$(document).ready(function() {
// Initialize the library (all console debuggers enabled)
Janus.init({debug: "all", callback: function() {
// Use a button to start the demo
$('#start').click(function() {
if(started)
return;
started = true;
$(this).attr('disabled', true).unbind('click');
// Make sure the browser supports WebRTC
if(!Janus.isWebrtcSupported()) {
bootbox.alert("No WebRTC support... ");
return;
}
// Create session
janus = new Janus(
{
server: server,
success: function() {
// Attach to Voice Mail test plugin
janus.attach(
{
plugin: "janus.plugin.voicemail",
opaqueId: opaqueId,
success: function(pluginHandle) {
$('#details').remove();
vmailtest = pluginHandle;
Janus.log("Plugin attached! (" + vmailtest.getPlugin() + ", id=" + vmailtest.getId() + ")");
$('#voicemail').removeClass('hide').show();
$('#start').removeAttr('disabled').html("Stop")
.click(function() {
$(this).attr('disabled', true);
janus.destroy();
});
$('#record').removeAttr('disabled').html("Record")
.click(function() {
$(this).attr('disabled', true);
startRecording();
});
},
error: function(error) {
Janus.error(" -- Error attaching plugin...", error);
bootbox.alert("Error attaching plugin... " + error);
},
consentDialog: function(on) {
Janus.debug("Consent dialog should be " + (on ? "on" : "off") + " now");
if(on) {
// Darken screen and show hint
$.blockUI({
message: '<div><img src="up_arrow.png"/></div>',
css: {
border: 'none',
padding: '15px',
backgroundColor: 'transparent',
color: '#aaa',
top: '10px',
left: (navigator.mozGetUserMedia ? '-100px' : '300px')
} });
} else {
// Restore screen
$.unblockUI();
}
},
onmessage: function(msg, jsep) {
Janus.debug(" ::: Got a message :::");
Janus.debug(msg);
var event = msg["voicemail"];
Janus.debug("Event: " + event);
if(event != undefined && event != null) {
if(event === "event") {
if(msg["status"] !== undefined && msg["status"] !== null) {
var status = msg["status"];
if(status === 'starting') {
$('#record')
.removeClass("btn-danger").addClass("btn-default")
.text("Starting, please wait...");
} else if(status === 'started') {
$('#record')
.removeClass("btn-default").addClass("btn-info")
.text("Started");
} else if(status === 'done') {
$('#record')
.removeClass("btn-info").addClass("btn-success")
.text("Done!");
$('#download').attr('href', msg["recording"]);
$('#listen').click(function() {
$('#rec').remove();
$('#done').parent().append(
'<audio id="rec" style="width:100%;height:100%;" autoplay controls preload="auto">' +
'<source id="opusrec" src="' + msg["recording"] + '" type="audio/ogg""></source>' +
'Your browser doesn\'t support the playout of Opus files' +
'</audio>'
);
$('#opusrec').attr('type', 'audio/ogg; codecs="opus"');
if($('#opusrec').get(0).error) {
bootbox.alert("Couldn't play the Opus recording (" + $('#opusrec').get(0).error + "), try downloading it instead");
}
return false;
});
$('#done').removeClass('hide').show();
vmailtest.hangup();
}
} else if(msg["error"] !== undefined && msg["error"] !== null) {
bootbox.alert(msg["error"], function() {
window.location.reload();
});
}
}
}
if(jsep !== undefined && jsep !== null) {
Janus.debug("Handling SDP as well...");
Janus.debug(jsep);
vmailtest.handleRemoteJsep({jsep: jsep});
}
},
onlocalstream: function(stream) {
// We're not going to attach the local audio stream
},
onremotestream: function(stream) {
// We're not going to receive anything from the plugin
},
oncleanup: function() {
Janus.log(" ::: Got a cleanup notification :::");
}
});
},
error: function(error) {
Janus.error(error);
bootbox.alert(error, function() {
window.location.reload();
});
},
destroyed: function() {
window.location.reload();
}
});
});
}});
});
function startRecording() {
// Negotiate WebRTC now
vmailtest.createOffer(
{
media: { audioRecv: false, video: false}, // We're going to only send, and not receive, audio
success: function(jsep) {
Janus.debug("Got SDP!");
Janus.debug(jsep);
var publish = { "request": "record" };
vmailtest.send({"message": publish, "jsep": jsep});
},
error: function(error) {
Janus.error("WebRTC error:", error);
bootbox.alert("WebRTC error... " + JSON.stringify(error));
}
});
}
|