0){
if(!btnRespond.visible && !sessionIsEnded) {
countdownDuration = Number(event.data.msgVal.AlertDuration);
var timeDelta:Number = trackAlertReceived();
previousAlertReceived = new Date();
showAlert(event.data.msgVal.AlertText);
}
}
break;
case CustomSyncMessage.END_SESSION:
if(settings.syncConnector.isArchive){
archiveSessionEnd();
}
//completely remove interface so as not to receive any polls after session end
sessionIsEnded = true;
recordParticipantLog();
// Open final website for participants to show certificate and survey.
var url:String = settings.baseServiceUrl + "/index/result?principalid=" + user.Id + "&scoid=" + settings.room_ScoID;
ExternalInterface.call("window.open('" + url + "')", 1);
//Application.application.LOG("SESSION_END received " + "timestamp = " + Utilities.currentDateTimeString() + " sessionIsEnded = " + sessionIsEnded.toString());
Application.application.clearInterface();
break;
}
}
}
/*****************************************************************************/
private function archiveSessionEnd():void{
var url:String = settings.baseServiceUrl + "/static/services/engagement/service.asmx/ArchiveSessionEnd?"
+ "scoId=" + settings.room_ScoID
+ "&principalId=" + user.Id
+ "&firstName=" + user.FirstName
+ "&lastName=" + user.LastName
+ "&email=" +user.Email;
var service:HTTPService = new HTTPService();
service.url = url;
service.contentType="application/x-www-form-urlencoded";
service.resultFormat = "object";
service.method = "POST";
service.addEventListener(ResultEvent.RESULT, archiveSessionEnd_resultHandler);
//service.addEventListener(FaultEvent.FAULT, Application.application.cpeservice_faultHandler);
service.send();
}
protected function archiveSessionEnd_resultHandler(event:ResultEvent):void{
var result:Number = Number(event.result.int);
if(result == -1)
{
Alert.show("Problem recording end of session.");
}
}
/*****************************************************************************/
/*****************************************************************************/
private function trackAlertReceived():Number{
var timeDelta:Number = differenceBetweenDates(previousAlertReceived, new Date());
recordAlertReceived(timeDelta);
//Application.application.LOG("Alert time delta = " + timeDelta + "seconds");
return timeDelta;
}
private function differenceBetweenDates(date1:Date, date2:Date):Number{
var tempDate:Date = new Date(date2.time - date1.time);
var difference:Number = Math.abs(tempDate.time / msInSec);
return difference;
}
/*****************************************************************************/
protected function showAlert(alertText:String):void {
recordEngagementDisplay();
startBlinkingBackground();
lblRespond.text = alertText;
lblRespond.visible = true;
btnRespond.enabled = true;
btnRespond.visible = true;
Application.application.LOG("Showing engagement button. timestamp = " + Utilities.currentDateTimeString());
//Application.application.LOG("Play alert sound = "+ playAlertSound);
if(playAlertSound)
audibleAlert.play(); // audible ding
startResponseCountdown();
}
protected function hideAlert():void {
stopBlinkingBackground(); // stop background blinking
lblRespond.visible = false; // hide response button
btnRespond.visible = false;
btnRespond.enabled = false;
stopResponseCountdown(); // stop countdown timer
}
/*****************************************************************************/
/*****************************************************************************/
private function getSessionCookie():String{
if(ExternalInterface.available){
var queryString:String = ExternalInterface.call("window.location.search.substring",1);
if(queryString){
var paramsFromUrl:Object = {};
var params:Array = queryString.split('&');
var length:uint = params.length;
for (var i:uint=0,index:int=-1; i 0)
{
var key:String = kvPair.substring(0,index);
var value:String = kvPair.substring(index+1);
paramsFromUrl[key] = value;
}
}
}
var session:String = paramsFromUrl["session"];
return session;
}
else{
return "";
}
}
protected function getCommonInfo():void {
var url:String = '/api/xml?action=common-info';
if(sessionCookie != null && sessionCookie.length > 0){
url += '&session=' + sessionCookie;
}
//Application.application.LOG(url);
var service:HTTPService = new HTTPService();
service.url = url;
service.contentType="application/x-www-form-urlencoded";
service.resultFormat = "xml";
service.method = "GET";
service.addEventListener(ResultEvent.RESULT, commonInfo_resultHandler);
service.send();
}
private var commonInfoCookie:Boolean = false;
protected function commonInfo_resultHandler(event:ResultEvent):void {
var commonInfo:XML = XML(event.result);
//Application.application.LOG(commonInfo.toXMLString());
if((commonInfo..user == undefined || commonInfo..user == null)){
if(commonInfoCookie){
//send message to host, can't track this person
settings.syncConnector.dispatchSyncMessage(CustomSyncMessage.PARTICIPANT_INVALID_ID, String(settings.syncConnector.userName), true);
Application.application.LOG("Sending participant id invalid message");
Application.application.clearInterface();
}else{
Application.application.LOG("Cookie doesn't exist, using alternate method");
commonInfoCookie = true;
try{
sessionCookie = getSessionCookie();
}
catch (err:Error){
Application.application.LOG("Problem getting session cookie from alternate method.");
}
getCommonInfo();
}
}
else{
Application.application.LOG("CommonInfo user exists.");
user.Id = Number(XML(commonInfo..user).attribute("user-id"));
user.Email = XML(commonInfo..user).descendants("login");
user.RoomId = settings.syncConnector.userID;
servicePrincipalInfo.send();
}
}
protected function principalInfo_resultHandler(event:ResultEvent):void {
var principalInfo:XML = XML(event.result);
user.FirstName = principalInfo..contact.child("first-name");
user.LastName = principalInfo..contact.child("last-name");
Application.application.LOG("Principal_ID = " + user.Id.toString() + " Email = " + user.Email + " Name = " + user.FirstName + " " + user.LastName);
if(settings.syncConnector.isArchive){
Application.application.LOG("This is a recording.");
}
if(!userSent) {
settings.syncConnector.dispatchSyncMessage(CustomSyncMessage.USER_ADD_MSG, user, true);
userSent = true;
}
}
/*****************************************************************************/
protected function recordAlertReceived(timeDelta:Number):void {
var url:String = settings.baseServiceUrl + "/static/services/engagement/service.asmx/TrackEngagementReceived?"
+ "scoId=" + settings.room_ScoID
+ "&principalId=" + user.Id
+ "&timeDelta=" + timeDelta;
var service:HTTPService = new HTTPService();
service.url = url;
service.contentType="application/x-www-form-urlencoded";
service.resultFormat = "object";
service.method = "POST";
service.addEventListener(ResultEvent.RESULT, recordAlertReceived_resultHandler);
//service.addEventListener(FaultEvent.FAULT, Application.application.cpeservice_faultHandler);
service.send();
}
protected function recordAlertReceived_resultHandler(event:ResultEvent):void {
//var result:Number = Number(event.result.int);
}
/*****************************************************************************/
private var responseTimer:Timer;
protected function recordEngagementDisplay():void {
var url:String = settings.baseServiceUrl + "/static/services/engagement/service.asmx/TrackEngagementDisplay?"
+ "scoId=" + settings.room_ScoID
+ "&principalId=" + user.Id;
//Application.application.LOG(url);
var service:HTTPService = new HTTPService();
service.url = url;
service.contentType="application/x-www-form-urlencoded";
service.resultFormat = "object";
service.method = "POST";
service.addEventListener(ResultEvent.RESULT, recordEngagementDisplay_resultHandler);
service.addEventListener(FaultEvent.FAULT, Application.application.cpeservice_faultHandler);
service.send();
}
protected function recordEngagementDisplay_resultHandler(event:ResultEvent):void {
var result:Number = Number(event.result.int);
//currentEngagementKey = result;
// if(result == -1)
// Application.application.LOG('Phantom Ping received');
if(result == -99)
Alert.show("Problem recording engagement display.");
settings.syncConnector.dispatchSyncMessage(CustomSyncMessage.USER_ADD_MSG, user, true);
}
protected function recordEngagementResponse():void {
var url:String = settings.baseServiceUrl + "/static/services/engagement/service.asmx/TrackEngagementResponse?"
+ "scoId=" + settings.room_ScoID
+ "&principalId=" + user.Id;
//+ "engagementKey=" + currentEngagementKey.toString();
//Application.application.LOG(url);
var service:HTTPService = new HTTPService();
service.url = url;
service.contentType="application/x-www-form-urlencoded";
service.resultFormat = "object";
service.method = "POST";
service.addEventListener(ResultEvent.RESULT, recordEngagementResponse_resultHandler);
service.addEventListener(FaultEvent.FAULT, Application.application.cpeservice_faultHandler);
service.send();
}
protected function recordEngagementResponse_resultHandler(event:ResultEvent):void {
var result:Number = Number(event.result.int);
if(result == -1){
btnRespond.enabled = true;
Alert.show("Problem recording engagement response.");
}
else{
hideAlert();
}
}
/*****************************************************************************/
/*****************************************************************************/
/** Participant Message **/
/*****************************************************************************/
protected function recordParticipantMessage(msg:String):void {
if(Application.application.settings.syncConnector.roomSCOID > 0 ){
var url:String = Application.application.settings.baseServiceUrl + "/static/services/engagement/service.asmx/RecordParticipantMessage?"
+ "scoId=" + Application.application.settings.syncConnector.roomSCOID.toString()
+ "&principalId=" + user.Id
+ "&message=" + msg;
//Application.application.LOG(url);
var service:HTTPService = new HTTPService();
service.url = url;
service.contentType="application/x-www-form-urlencoded";
service.resultFormat = "object";
service.method = "POST";
service.addEventListener(ResultEvent.RESULT, recordParticipantMessage_resultHandler);
//service.addEventListener(FaultEvent.FAULT, Application.application.cpeservice_faultHandler);
service.send();
}
}
protected function recordParticipantMessage_resultHandler(event:ResultEvent):void{
//don't care about result
}
/*****************************************************************************/
/*****************************************************************************/
protected function recordParticipantLog():void {
var details:String = htmlEscape(Application.application.logText);
//Application.application.LOG('details = ' + details);
var url:String = settings.baseServiceUrl + "/static/services/engagement/service.asmx/RecordParticipantLog?"
+ "scoId=" + settings.room_ScoID
+ "&principalId=" + user.Id
+ "&details=" + details;
//+ "engagementKey=" + currentEngagementKey.toString();
//Application.application.LOG(url);
var service:HTTPService = new HTTPService();
service.url = url;
service.contentType="application/x-www-form-urlencoded";
service.resultFormat = "object";
service.method = "POST";
service.addEventListener(ResultEvent.RESULT, recordParticipantLog_resultHandler);
//service.addEventListener(FaultEvent.FAULT, Application.application.cpeservice_faultHandler);
service.send();
}
protected function recordParticipantLog_resultHandler(event:ResultEvent):void {
//blackhole log errors
}
public function htmlEscape(str:String):String
{
return XML( new XMLNode( XMLNodeType.TEXT_NODE, str ) ).toXMLString();
}
/*****************************************************************************/
private function startResponseCountdown():void {
responseTimer = new Timer(countdownDuration,1);
responseTimer.addEventListener(TimerEvent.TIMER, responseCountdown_tick);
responseTimer.start();
}
private function responseCountdown_tick(evt:TimerEvent):void {
hideAlert();
}
private function stopResponseCountdown():void {
if(responseTimer != null){
responseTimer.stop();
responseTimer.removeEventListener(TimerEvent.TIMER, responseCountdown_tick);
responseTimer = null;
}
}
private var timerAtStart:int = 0;
private var sessionActive:Timer;
/*****************************************************************************/
/*****************************************************************************/
protected function btnRespond_clickHandler(event:MouseEvent):void {
btnRespond.enabled = false;
recordEngagementResponse();
}
protected function chkPlaySound_clickHandler(event:MouseEvent):void {
playAlertSound = chkPlaySound.selected;
}
/*****************************************************************************/
]]>