@@ -629,6 +629,9 @@ var CPP_EXAMPLES = {
629629 cppVirtualLink : 'cpp-example-code/cpp-virtual-method.cpp' ,
630630}
631631
632+
633+ // BEGIN -- Codeopticon learner interface
634+
632635var chatBox = undefined ;
633636function createChatBox ( ) {
634637 assert ( ! chatBox ) ;
@@ -645,12 +648,18 @@ function createChatBox() {
645648
646649function chatMsgSent ( id , user , msg ) {
647650 $ ( "#chat_div" ) . chatbox ( "option" , "boxManager" ) . addMsg ( id , msg ) ;
648- logEvent ( { type : 'opt-client-chat' , text : msg , sid : loggingSocketIO ? loggingSocketIO . id : undefined } ) ;
651+ logEventCodeopticon ( { type : 'opt-client-chat' ,
652+ text : msg ,
653+ sid : codeopticonSocketIO ? codeopticonSocketIO . id : undefined
654+ } ) ;
649655}
650656
651657// only called when the user hits the X button to explicitly close the chat box
652658function chatBoxClosed ( id ) {
653- logEvent ( { type : 'opt-client-chat' , text : '[closed chat box]' , sid : loggingSocketIO ? loggingSocketIO . id : undefined } ) ;
659+ logEventCodeopticon ( { type : 'opt-client-chat' ,
660+ text : '[closed chat box]' ,
661+ sid : codeopticonSocketIO ? codeopticonSocketIO . id : undefined
662+ } ) ;
654663}
655664
656665// called when the user toggles the chat box open or close
@@ -659,9 +668,56 @@ function chatBoxToggled(visible) {
659668 if ( visible ) {
660669 msg = '[maximized chat box]' ;
661670 }
662- logEvent ( { type : 'opt-client-chat' , text : msg , sid : loggingSocketIO ? loggingSocketIO . id : undefined } ) ;
671+ logEventCodeopticon ( { type : 'opt-client-chat' ,
672+ text : msg ,
673+ sid : codeopticonSocketIO ? codeopticonSocketIO . id : undefined
674+ } ) ;
675+ }
676+
677+ function initCodeopticon ( ) {
678+ // connect on-demand in logEventCodeopticon(), not here
679+ //codeopticonSocketIO = io('http://104.237.139.253:5000/userlog'); // PRODUCTION_PORT
680+ //codeopticonSocketIO = io('http://104.237.139.253:5001/userlog'); // DEBUG_PORT
681+ codeopticonSocketIO = io ( 'http://localhost:5000/userlog' ) ; // localhost debugging
682+
683+ if ( codeopticonSocketIO ) {
684+ codeopticonSocketIO . on ( 'connect' , function ( ) {
685+ //console.log('CONNECTED and emitting', logEventQueue.length, 'events');
686+
687+ if ( logEventQueue . length > 0 ) {
688+ // the reconnectAttempts field that denotes how many times you've
689+ // attempted to reconnect (which is also how many times you've
690+ // been kicked off by the logging server for, say, being idle).
691+ // add this as an extra field on the FIRST event
692+ if ( reconnectAttempts > 0 ) {
693+ logEventQueue [ 0 ] . reconnectAttempts = reconnectAttempts ;
694+ }
695+
696+ while ( logEventQueue . length > 0 ) {
697+ codeopticonSocketIO . emit ( 'opt-client-event' , logEventQueue . pop ( ) ) ;
698+ }
699+ }
700+ assert ( logEventQueue . length === 0 ) ;
701+
702+ reconnectAttempts ++ ;
703+ } ) ;
704+
705+ codeopticonSocketIO . on ( 'opt-codeopticon-observer-chat' , function ( msg ) {
706+ if ( ! chatBox ) {
707+ createChatBox ( ) ;
708+ } else {
709+ $ ( "#chat_div" ) . chatbox ( "option" , "hidden" , false ) ;
710+ $ ( "#chat_div" ) . chatbox ( "showContent" ) ;
711+ }
712+
713+ $ ( "#chat_div" ) . chatbox ( "option" , "boxManager" ) . addMsg ( 'Tutor' , msg . text ) ;
714+ } ) ;
715+ }
663716}
664717
718+ // END -- Codeopticon learner interface
719+
720+
665721$ ( document ) . ready ( function ( ) {
666722 setSurveyHTML ( ) ;
667723
@@ -798,44 +854,7 @@ $(document).ready(function() {
798854
799855 initAceAndOptions ( ) ; // do this after genericOptFrontendReady
800856
801- // connect on-demand in logEvent(), not here
802- //loggingSocketIO = io('http://104.237.139.253:5000/userlog'); // PRODUCTION_PORT
803- //loggingSocketIO = io('http://104.237.139.253:5001/userlog'); // DEBUG_PORT
804-
805-
806- if ( loggingSocketIO ) {
807- loggingSocketIO . on ( 'connect' , function ( ) {
808- //console.log('CONNECTED and emitting', logEventQueue.length, 'events');
809-
810- if ( logEventQueue . length > 0 ) {
811- // the reconnectAttempts field that denotes how many times you've
812- // attempted to reconnect (which is also how many times you've
813- // been kicked off by the logging server for, say, being idle).
814- // add this as an extra field on the FIRST event
815- if ( reconnectAttempts > 0 ) {
816- logEventQueue [ 0 ] . reconnectAttempts = reconnectAttempts ;
817- }
818-
819- while ( logEventQueue . length > 0 ) {
820- loggingSocketIO . emit ( 'opt-client-event' , logEventQueue . pop ( ) ) ;
821- }
822- }
823- assert ( logEventQueue . length === 0 ) ;
824-
825- reconnectAttempts ++ ;
826- } ) ;
827-
828- loggingSocketIO . on ( 'opt-codeopticon-observer-chat' , function ( msg ) {
829- if ( ! chatBox ) {
830- createChatBox ( ) ;
831- } else {
832- $ ( "#chat_div" ) . chatbox ( "option" , "hidden" , false ) ;
833- $ ( "#chat_div" ) . chatbox ( "showContent" ) ;
834- }
835-
836- $ ( "#chat_div" ) . chatbox ( "option" , "boxManager" ) . addMsg ( 'Tutor' , msg . text ) ;
837- } ) ;
838- }
857+ initCodeopticon ( ) ;
839858
840859 $ ( "#createTestsLink" ) . click ( function ( ) {
841860 initTestcasesPane ( '#testCasesPane' ) ;
0 commit comments