Git Repository Public Repository

CPE_learningsite

URLs

Copy to Clipboard

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:components="com.adobe.sync.components.*" width="100%" height="100%" initialize="init()">
	<mx:Script>
		<![CDATA[
			import com.adobe.sync.events.SyncSwfEvent;
			
			import models.CustomSyncMessage;
			import models.Settings;
			import models.User;
			
			import mx.controls.Alert;
			import mx.core.Application;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
			private var msInSec:uint = 1000;
			private var msInMin:uint = msInSec * 60;
			private var msInHr:uint = msInMin * 60;
			
			[Bindable] private var settings:Settings;
			[Embed(source="assets/ding.mp3")] private var alertSound:Class;
			private var audibleAlert:Sound;
			[Bindable] private var playAlertSound:Boolean = true;
			[Bindable] private var user:User = new User();
			private var userSent:Boolean = false;
			private var countdownDuration:Number = msInMin;
			private var alertText:String;
			private var sessionCookie:String = null;
			private var previousAlertReceived:Date = new Date();
			//private var currentEngagementKey:int;
			private var sessionIsEnded:Boolean = false;
			
			/*****************************************************************************/
			private function init():void{
				audibleAlert = new alertSound() as Sound;
				settings = EngagementPod(Application.application).settings;
				settings.syncConnector.addEventListener(SyncSwfEvent.SYNC_MSG_RCVD, syncMessageReceived);
				settings.syncConnector.addEventListener(SyncSwfEvent.ROLE_CHANGED,syncConnector_roleChangedHandler);
				
				getCommonInfo();
			}			
			/*****************************************************************************/
			
			
			/*****************************************************************************/
			protected function syncConnector_roleChangedHandler(event:SyncSwfEvent):void {
				settings.syncConnector.dispatchSyncMessage(CustomSyncMessage.USER_REMOVE_MSG, user, true);
			}
			/*****************************************************************************/
			
			
			/*****************************************************************************/
			private var blinkTimer:Timer;
			private function startBlinkingBackground():void{
				blinkTimer = new Timer(300);
				blinkTimer.addEventListener(TimerEvent.TIMER, blink_tick);
				blinkTimer.start();
			}
			private function blink_tick(evt:TimerEvent):void {
				if((blinkTimer.currentCount % 2) == 0){
					fadeBackgroundColorForward.play();
				}
				else{
					fadeBackgroundColorReverse.play();
				}
			}
			private function stopBlinkingBackground():void{
				blinkTimer.stop();
				blinkTimer.removeEventListener(TimerEvent.TIMER, blink_tick);
				blinkTimer = null;
				fadeBackgroundColorDefault.play();
			}
			/*****************************************************************************/
						
						
			/*****************************************************************************/
			protected function syncMessageReceived(event:SyncSwfEvent):void {
				
				var msg:String ="Message received: " + event.data.msgNm + " timestamp = " + Utilities.currentDateTimeString()  + " role = " + settings.syncConnector.role;
				if(user != null){
					msg += " principal_id = " + user.Id;
				}
				else{
					msg += " principal_id = -1";
				}
				Application.application.LOG(msg);
				recordParticipantMessage(event.data.msgNm);
				
				if(settings.syncConnector.role == "viewer" && settings.syncConnector.isCaughtUp) {
					switch (event.data.msgNm) {
						case CustomSyncMessage.PARTICIPANT_ALERT:
							if(user.Id > 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<length; i++)
						{
							var kvPair:String = params[i];
							if ((index = kvPair.indexOf("=")) > 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;
			}
			/*****************************************************************************/
		]]>
	</mx:Script>
	
	<ds:AnimateColor xmlns:ds="com.effects.*"
					 id="fadeBackgroundColorForward" duration="150" fromValue="#004B73"
					 isStyle="true" property="backgroundColor" target="{participantPanel}"
					 toValue="#FFFFFF"/>
	<ds:AnimateColor xmlns:ds="com.effects.*"
					 id="fadeBackgroundColorReverse" duration="150" fromValue="#FFFFFF"
					 isStyle="true" property="backgroundColor" target="{participantPanel}"
					 toValue="#004B73"/>
	<ds:AnimateColor xmlns:ds="com.effects.*"
					 id="fadeBackgroundColorDefault" duration="180" fromValue="#FFFFFF"
					 isStyle="true" property="backgroundColor" target="{participantPanel}"
					 toValue="#CCCCCC"/>
	
	<mx:Panel id="participantPanel" left="0" right="0" top="0" bottom="0"
			  backgroundColor="#CCCCCC">
		<mx:VBox width="100%" height="100%" horizontalAlign="center" paddingLeft="10"
				 verticalAlign="middle">
			<mx:CheckBox id="chkPlaySound" label="Un-click to disable polling audio notification"
						 click="chkPlaySound_clickHandler(event)" selected="true"/>
			<mx:VBox width="100%" height="100%" fontSize="18" horizontalAlign="center"
					 verticalAlign="middle">
				<mx:Text id="lblRespond" visible="false" width="100%" text="" textAlign="center"/>
				<mx:Button id="btnRespond" visible="false" label="Respond"
						   click="btnRespond_clickHandler(event)"/>
			</mx:VBox>
			
		</mx:VBox>
	</mx:Panel>
	<mx:HTTPService id="serviceCommonInfo" result="commonInfo_resultHandler(event)" fault="Application.application.connectservice_faultHandler(event)" resultFormat="xml" url="/api/xml?action=common-info" />
	<mx:HTTPService id="servicePrincipalInfo" result="principalInfo_resultHandler(event)" fault="Application.application.connectservice_faultHandler(event)" resultFormat="xml" url="{'/api/xml?action=principal-info&amp;principal-id=' + user.Id}" />
</mx:Canvas>

Commits for CPE_learningsiteCPEFlex/EngagementPod/src/Participant.mxml

Diff revisions: vs.
Revision Author Commited Message
4cd176 ... v.shishlov Fri 27 Aug, 2021 14:33:17 +0000

initial commit