function Miles(element, params) {
// private attributes
var self = this;
// private instanceId
if (!Miles.instances)
Miles.instances = 0;
// public attributes
this.instanceId = Miles.instances++;
this.element = element;
this.connected = false;
this.imageIteration = 0;
this.width = 320;
this.height = 240;
// private attributes
var scxmlURL = "localhost:8080"
var reflectorIp = "88.131.107.12"
var email = "user@smartvortex.eu";
var problemName = "webconfero";
var remoteEmail = "other@smartvortex.eu";
var participants = []; // empty array
var videoCompressions = [
{ value: 'jpeg', label: "JPEG" },
{ value: 'h263', label: "H.263" },
{ value: 'h264', label: "H.264" },
];
var videoCompression = "";
var audioEncodings = [
{ value: 'pcm', label: "PCM" },
{ value: 'ulaw', label: "uLaw" },
{ value: 'ogg', label: "Ogg Theora" },
];
var audioEncoding = "";
var repollInterval = {
image: 50,
chat: 500,
participants: 1000
};
var surpressPublication = false; // do not publish changes performed from subscriptions
var showVideo = true;
var enableAudio = true;
var stopChatScrolling = false;
var activateCamera = true;
var openMicrophone = true;
var videoFramerate = 25;
var videoHeight = self.height;
var videoWidth = self.width;
// override with parameters if given
this.params = params;
if (params && params.scxmlURL) scxmlURL = params.scxmlURL;
if (params && params.reflectorIp) reflectorIp = params.reflectorIp;
if (params && params.email) email = params.email;
if (params && params.problemName) problemName = params.problemName;
// called when dojo loaded all requirements below
this.connect = function() {
var query = "";
query += "?reflector=" + encodeURIComponent(reflectorIp);
query += "&userid=" + encodeURIComponent(email);
query += "&session=" + encodeURIComponent(problemName);
self.xhr.get({
// The URL to request
url: "http://" + scxmlURL + "/miles/start" + query,
// handleAs:"text",
error: function(err) {
console.log(err);
},
load: function(result) {
self.connected = true;
// toggle connect button to disconnect
self.connectDropDown.dropDown.onCancel(true);
self.controlElem.replaceChild(self.controlDropDown.domNode, self.connectDropDown.domNode);
showChat();
// trigger continuous updates
refreshImage();
getChatText();
getParticipants();
}
});
}
this.disconnect = function() {
var query = "";
query += "?reflector=" + encodeURIComponent(reflectorIp);
query += "&userid=" + encodeURIComponent(email);
query += "&session=" + encodeURIComponent(problemName);
self.xhr.get({
// The URL to request
url: "http://" + scxmlURL + "/miles/stop" + query,
// handleAs:"text",
error: function(err) {
console.log(err);
},
load: function(result) {
self.connected = false;
hideChat();
self.controlDropDown.dropDown.onCancel(true);
self.controlElem.replaceChild(self.connectDropDown.domNode, self.controlDropDown.domNode);
}
});
}
var hideChat = function() {
// hide chat elements until connected
for(var key in self.chatElems) {
if (self.chatElems.hasOwnProperty(key) && "style" in self.chatElems[key])
self.chatElems[key].style.display = "none";
}
}
var showChat = function() {
for(var key in self.chatElems) {
if (self.chatElems.hasOwnProperty(key) && "style" in self.chatElems[key])
self.chatElems[key].style.display = "";
}
}
var getParticipants = function() {
if (!self.connected)
return;
var query = "";
self.xhr.get({
// The URL to request
url: "http://" + scxmlURL + "/miles/participants" + query,
handleAs:"json",
error: function(err) {
console.log(err);
setTimeout(getParticipants, repollInterval.participants);
},
load: function(result) {
if (result.participants) {
participants = result.participants;
}
setTimeout(getParticipants, repollInterval.participants);
}
});
}
// fetch a base64 encoded image and set it as the src attribute
var refreshImage = function() {
if (!self.connected)
return;
var query = "";
query += "?userid=" + encodeURIComponent(remoteEmail);
self.xhr.get({
// The URL to request
url: "http://" + scxmlURL + "/miles/thumbnail" + query,
handleAs:"text",
headers:{
"X-Content-Encoding": "base64"
},
error: function(err) {
console.log(err);
setTimeout(refreshImage, repollInterval.image);
},
load: function(result) {
self.pictureElem.src = "data:image/jpeg;base64," + result;
self.messageElem.innerHTML = self.imageIteration++;
setTimeout(refreshImage, repollInterval.image);
}
});
};
var getChatText = function() {
if (!self.connected)
return;
self.xhr.get({
// The URL to request
url: "http://" + scxmlURL + "/miles/gettext",
handleAs:"json",
error: function(err) {
console.log(err);
setTimeout(getChatText, repollInterval.chat);
},
load: function(result) {
if (result.message) {
self.chatOutputElem.innerHTML += result.message + '
';
if (!stopChatScrolling)
self.chatOutputElem.scrollTop = self.chatOutputElem.scrollHeight;
}
setTimeout(getChatText, repollInterval.chat);
}
});
};
require(["dojo/dom-construct",
"dojo/_base/xhr",
"dojo/dom",
"dojo/on",
"dojo/topic",
"dojo/_base/unload",
"dijit/form/DropDownButton",
"dijit/TooltipDialog",
"dijit/form/TextBox",
"dijit/form/Button",
"dijit/form/CheckBox",
"dijit/form/Select",
"dijit/form/NumberSpinner",
"dojo/ready"],
function(domConst,
xhr,
dom,
on,
topic,
baseUnload,
DropDownButton,
TooltipDialog,
TextBox,
Button,
CheckBox,
Select,
NumberSpinner,
ready) {
ready(function() {
self.xhr = xhr;
// if we were passed an id, resolve to dom node
if (typeof(element) === 'string') {
element = dom.byId(element);
}
element.style.width = self.width + "px";
baseUnload.addOnWindowUnload(function(){
// have a call to close the session here
});
// dynamically assemble the DOM we need
element.appendChild(domConst.toDom('\
\
\
\
![]() \
\
| \
||
\
\
| ||
\
\
| \
\ | |
\ | \
Problem Name: | |
Your Email: | |
Other Email: | |
Reflector Host: | |
Video Server: | |