| 1 |
/* eslint-disable no-unused-vars */ |
| 2 |
|
| 3 |
// We use this shared JavaScript file as a simple way to have all demos |
| 4 |
// refer to the same settings, e.g., in terms of which server to connect |
| 5 |
// to or which STUN/TURN servers to use. This is helpful any time Janus |
| 6 |
// and its demos need to be deployed in a different environment, and |
| 7 |
// so all demos can be installed as are, by just updating the settings.js |
| 8 |
// file accordingly to account for the custom changes. |
| 9 |
// |
| 10 |
// We make use of this 'server' variable to provide the address of the |
| 11 |
// Janus API backend. By default, in this example we assume that Janus is |
| 12 |
// co-located with the web server hosting the HTML pages but listening |
| 13 |
// on a different port (8088, the default for HTTP in Janus), which is |
| 14 |
// why we make use of the 'window.location.hostname' base address. Since |
| 15 |
// Janus can also do HTTPS, and considering we don't really want to make |
| 16 |
// use of HTTP for Janus if your demos are served on HTTPS, we also rely |
| 17 |
// on the 'window.location.protocol' prefix to build the variable, in |
| 18 |
// particular to also change the port used to contact Janus (8088 for |
| 19 |
// HTTP and 8089 for HTTPS, if enabled). |
| 20 |
// In case you place Janus behind an Apache frontend (as we did on the |
| 21 |
// online demos at http://janus.conf.meetecho.com) you can just use a |
| 22 |
// relative path for the variable, e.g.: |
| 23 |
// |
| 24 |
// var server = "/janus"; |
| 25 |
// |
| 26 |
// which will take care of this on its own. |
| 27 |
// |
| 28 |
// If you want to use the WebSockets frontend to Janus, instead (which |
| 29 |
// is what we recommend, since they're more efficient than the long polling |
| 30 |
// we do with HTTP), you'll have to pass a different kind of address, e.g.: |
| 31 |
// |
| 32 |
// var server = "ws://" + window.location.hostname + ":8188"; |
| 33 |
// |
| 34 |
// Of course this assumes that support for WebSockets has been built in |
| 35 |
// when compiling the server. Notice that the "ws://" prefix assumes |
| 36 |
// plain HTTP usage, so "wss://" should be used instead when using |
| 37 |
// WebSockets on HTTPS.// |
| 38 |
// |
| 39 |
// If you have multiple options available, and want to let the library |
| 40 |
// autodetect the best way to contact your server (or pool of servers), |
| 41 |
// you can also pass an array of servers, e.g., to provide alternative |
| 42 |
// means of access (e.g., try WebSockets first and, if that fails, fall |
| 43 |
// back to plain HTTP) or just have failover servers: |
| 44 |
// |
| 45 |
// var server = [ |
| 46 |
// "ws://" + window.location.hostname + ":8188", |
| 47 |
// "/janus" |
| 48 |
// ]; |
| 49 |
// |
| 50 |
// This will tell the library to try connecting to each of the servers |
| 51 |
// in the presented order. The first working server will be used for |
| 52 |
// the whole session. |
| 53 |
// |
| 54 |
var server = null; |
| 55 |
if(window.location.protocol === 'http:') |
| 56 |
server = "http://" + window.location.hostname + ":8088/janus"; |
| 57 |
else |
| 58 |
server = "https://" + window.location.hostname + ":8089/janus"; |
| 59 |
|
| 60 |
// When creating a Janus object, we can also specify which STUN/TURN |
| 61 |
// servers we'd like to use to gather additional candidates. This is |
| 62 |
// done by passing an "iceServers" property when creating the Janus |
| 63 |
// object, meaning that the same set of servers will be used for all |
| 64 |
// PeerConnections that will be initialized within the context of the |
| 65 |
// new Janus session. When no iceServers object is provided, the janus.js |
| 66 |
// library automatically uses the free Google STUN servers, which means |
| 67 |
// it's equivalent to setting: |
| 68 |
// |
| 69 |
// var iceServers = [{urls: "stun:stun.l.google.com:19302"}]; |
| 70 |
// |
| 71 |
// Here are some examples of how an iceServers field may look like to |
| 72 |
// support TURN instead. Notice that, when a TURN server is configured, |
| 73 |
// there's no need to set a STUN one as well, since the TURN server will |
| 74 |
// be automatically contacted as a STUN server too, meaning it will be |
| 75 |
// used to gather both server reflexive and relay candidates. |
| 76 |
// |
| 77 |
// var iceServers = [{urls: "turn:yourturnserver.com:3478", username: "janususer", credential: "januspwd"}] |
| 78 |
// var iceServers = [{urls: "turn:yourturnserver.com:443?transport=tcp", username: "janususer", credential: "januspwd"}] |
| 79 |
// var iceServers = [{urls: "turns:yourturnserver.com:443?transport=tcp", username: "janususer", credential: "januspwd"}] |
| 80 |
// |
| 81 |
// By default we leave the iceServers variable empty, which again means |
| 82 |
// janus.js will fallback to the Google STUN server by default: |
| 83 |
// |
| 84 |
var iceServers = null; |