1+ ( function ( $ ) {
2+ var nodejshelper = {
3+
4+ operatorForced : false ,
5+
6+ socket : null ,
7+
8+ intervalSyncTimeout : null ,
9+ chatActivated : false ,
10+
11+ init : function ( ) {
12+ this . socket = io . connect ( nodejshelperHostConnect , { secure :nodejshelperConfig . secure } ) ;
13+
14+ this . socket . on ( 'connect' , this . onConnected ) ;
15+ this . socket . on ( 'newmessage' , this . onMessage ) ;
16+ this . socket . on ( 'syncforce' , this . syncForce ) ;
17+ this . socket . on ( 'usertyping' , this . usertyping ) ;
18+ this . socket . on ( 'operatortyping' , this . operatortyping ) ;
19+ this . socket . on ( 'userleftchat' , this . userleftchat ) ;
20+ this . socket . on ( 'userjoined' , this . userjoined ) ;
21+ this . socket . on ( 'addfileupload' , this . syncForce ) ;
22+ this . socket . on ( 'addfileuserupload' , this . syncForce ) ;
23+ this . socket . on ( 'userpostedmessage' , this . userpostedmessage ) ;
24+ this . socket . on ( 'userstartedpostmessage' , this . userstartedpostmessage ) ;
25+
26+ // Disable standard sync method
27+ // We will use node JS notifications
28+ clearTimeout ( lhinst . userTimeout ) ;
29+
30+ // Required to workflow to work correctly
31+ this . setupForceTimeout ( ) ;
32+
33+ } ,
34+
35+ setupForceTimeout : function ( ) {
36+ clearTimeout ( this . intervalSyncTimeout ) ;
37+ if ( nodejshelperConfig . sync == true && this . chatActivated == false ) {
38+ this . intervalSyncTimeout = setTimeout ( function ( ) {
39+ nodejshelper . operatorForced = true ;
40+ lhinst . syncusercall ( ) ;
41+ } , nodejshelperConfig . synctimeout * 1000 ) ;
42+ }
43+ } ,
44+
45+ syncForce : function ( chat_id ) {
46+ if ( lhinst . chat_id == chat_id ) {
47+ nodejshelper . operatorForced = true ;
48+ lhinst . syncusercall ( ) ;
49+ nodejshelper . chatActivated = true ;
50+ } else {
51+ lhinst . syncadmincall ( ) ;
52+ }
53+ } ,
54+
55+ onMessage : function ( messageData ) {
56+ if ( lhinst . chat_id ) {
57+
58+ if ( typeof messageData . data . data !== 'undefined' ) {
59+ if ( $ ( '#messagesBlock' ) . find ( '.usr-tit' ) . size ( ) > 0 && $ ( '#messagesBlock' ) . find ( '.usr-tit' ) . last ( ) . attr ( 'data-sender' ) == messageData . data . data . sender ) {
60+ messageData . data . result = messageData . data . data . ur ;
61+ } else {
62+ messageData . data . result = messageData . data . data . or ;
63+ }
64+
65+ messageData . data . uw = 'false' ;
66+ messageData . data . blocked = 'false' ;
67+ messageData . data . status = 'true' ;
68+ messageData . data . ott = '' ;
69+ messageData . data . op = '' ;
70+ messageData . data . error = 'false' ;
71+ messageData . data . message_id = messageData . data . data . id ;
72+
73+ lhinst . updateUserSyncInterface ( lhinst , messageData . data ) ;
74+ } ;
75+ clearTimeout ( lhinst . userTimeout ) ;
76+ } else {
77+ lhinst . syncadmincall ( ) ;
78+ }
79+ } ,
80+
81+ onConnected : function ( ) {
82+
83+ if ( lhinst . chat_id > 0 ) {
84+ nodejshelper . socket . emit ( 'join' , lhinst . chat_id ) ;
85+ } ;
86+ } ,
87+
88+ usertyping : function ( data ) {
89+ if ( data . status == false ) {
90+ $ ( '#user-is-typing-' + data . chat_id ) . fadeOut ( ) ;
91+ } else {
92+ $ ( '#user-is-typing-' + data . chat_id ) . fadeIn ( ) . text ( data . msg ) ;
93+ }
94+ } ,
95+
96+ operatortyping : function ( data ) {
97+ if ( lhinst . chat_id == data . chat_id ) {
98+ if ( data . status == false ) {
99+ setTimeout ( function ( ) {
100+ $ ( '#id-operator-typing' ) . fadeOut ( ) ;
101+ } , 1000 ) ;
102+ } else {
103+ $ ( '#id-operator-typing' ) . fadeIn ( ) . text ( data . msg ) ;
104+ }
105+ }
106+ } ,
107+
108+ syncforceaction : function ( chat_id ) {
109+ nodejshelper . socket . emit ( 'syncforce' , chat_id ) ;
110+ } ,
111+
112+ userleftchat : function ( chat_id ) {
113+ lhinst . syncadmincall ( ) ;
114+ } ,
115+
116+ userjoined : function ( chat_id ) {
117+ setTimeout ( function ( ) {
118+ lhinst . syncadmincall ( ) ;
119+ } , 4000 ) ;
120+ } ,
121+
122+ addmsguser : function ( inst ) {
123+ nodejshelper . socket . emit ( 'userpostedmessage' , { chat_id :inst . chat_id } ) ;
124+ } ,
125+
126+ addmsguserbefore : function ( inst ) {
127+ nodejshelper . socket . emit ( 'userstartedpostmessage' , { chat_id :inst . chat_id } ) ;
128+ } ,
129+
130+ userpostedmessage : function ( ) {
131+ lhinst . syncadmincall ( ) ;
132+ } ,
133+
134+ userstartedpostmessage : function ( ) {
135+ setTimeout ( function ( ) {
136+ lhinst . syncadmincall ( ) ;
137+ } , 5000 ) ; // Give 5 seconds for user message to be stored in database
138+ } ,
139+
140+ // Disable user timeout message
141+ syncusercall : function ( inst , data ) {
142+ clearTimeout ( inst . userTimeout ) ;
143+ nodejshelper . setupForceTimeout ( ) ;
144+ if ( nodejshelper . operatorForced == false ) {
145+ nodejshelper . socket . emit ( 'newmessage' , { chat_id :inst . chat_id , data :data } ) ;
146+ } ;
147+ nodejshelper . operatorForced = false ;
148+ } ,
149+
150+ addmsguserchatbox : function ( inst , data ) {
151+ nodejshelper . operatorForced = true ;
152+ nodejshelper . socket . emit ( 'newmessage' , { chat_id :inst . chat_id , data :data } ) ;
153+ return false ;
154+ } ,
155+
156+ addSynchroChat : function ( chat_id , message_id ) {
157+ if ( nodejshelper . socket ) {
158+ nodejshelper . socket . emit ( 'join' , chat_id ) ;
159+ } else {
160+ setTimeout ( function ( ) {
161+ nodejshelper . socket . emit ( 'join' , chat_id ) ;
162+ } , 1000 ) ;
163+ }
164+ } ,
165+
166+ removeSynchroChat : function ( chat_id ) {
167+ nodejshelper . socket . emit ( 'leave' , chat_id ) ;
168+ } ,
169+
170+ syncadmincall : function ( inst , data ) {
171+ clearTimeout ( inst . userTimeout ) ;
172+ } ,
173+
174+ userleftchatNotification : function ( chat_id ) {
175+ if ( nodejshelper . socket ) {
176+ nodejshelper . socket . emit ( 'userleftchat' , chat_id ) ;
177+ }
178+ } ,
179+
180+ addFileUserUpload : function ( chat_id ) {
181+ nodejshelper . socket . emit ( 'syncforce' , chat_id ) ;
182+ lhinst . syncusercall ( ) ;
183+ } ,
184+
185+ addFileUpload : function ( chat_id ) {
186+ nodejshelper . socket . emit ( 'syncforce' , chat_id ) ;
187+ lhinst . syncadmincall ( ) ;
188+ } ,
189+
190+ addRemoteCommand : function ( chat_id ) {
191+ nodejshelper . socket . emit ( 'syncforce' , chat_id ) ;
192+ } ,
193+
194+ typingStoppedUserInform : function ( data ) {
195+ nodejshelper . socket . emit ( 'usertyping' , data ) ;
196+ } ,
197+
198+ initTypingMonitoringUserInform : function ( data ) {
199+ nodejshelper . socket . emit ( 'usertyping' , data ) ;
200+ } ,
201+
202+ initTypingMonitoringAdminInform : function ( data ) {
203+ data . msg = nodejshelperConfig . typer ;
204+ nodejshelper . socket . emit ( 'operatortyping' , data ) ;
205+ } ,
206+
207+ typingStoppedOperatorInform : function ( data ) {
208+ nodejshelper . socket . emit ( 'operatortyping' , data ) ;
209+ }
210+
211+
212+ } ;
213+
214+ // Give half second for standard script to finish their job
215+ setTimeout ( function ( ) {
216+ nodejshelper . init ( ) ;
217+ } , 500 ) ;
218+
219+ LHCCallbacks . syncadmincall = nodejshelper . syncadmincall ;
220+ LHCCallbacks . syncusercall = nodejshelper . syncusercall ;
221+ LHCCallbacks . addmsgadmin = nodejshelper . syncforceaction ;
222+ LHCCallbacks . addmsguserchatbox = nodejshelper . addmsguserchatbox ;
223+ LHCCallbacks . addSynchroChat = nodejshelper . addSynchroChat ;
224+ LHCCallbacks . removeSynchroChat = nodejshelper . removeSynchroChat ;
225+ LHCCallbacks . initTypingMonitoringAdmin = nodejshelper . initTypingMonitoringAdmin ;
226+ LHCCallbacks . userleftchatNotification = nodejshelper . userleftchatNotification ;
227+ LHCCallbacks . addFileUserUpload = nodejshelper . addFileUserUpload ;
228+ LHCCallbacks . addFileUpload = nodejshelper . addFileUpload ;
229+ LHCCallbacks . typingStoppedUserInform = nodejshelper . typingStoppedUserInform ;
230+ LHCCallbacks . initTypingMonitoringUserInform = nodejshelper . initTypingMonitoringUserInform ;
231+ LHCCallbacks . initTypingMonitoringAdminInform = nodejshelper . initTypingMonitoringAdminInform ;
232+ LHCCallbacks . typingStoppedOperatorInform = nodejshelper . typingStoppedOperatorInform ;
233+ LHCCallbacks . operatorAcceptedTransfer = nodejshelper . syncforceaction ;
234+ LHCCallbacks . uservoted = nodejshelper . syncforceaction ;
235+ LHCCallbacks . addRemoteCommand = nodejshelper . addRemoteCommand ;
236+ LHCCallbacks . addmsguser = nodejshelper . addmsguser ;
237+ LHCCallbacks . addmsguserbefore = nodejshelper . addmsguserbefore ;
238+
239+ // Additional options
240+ lhinst . appendSyncArgument = '/(render)/true' ;
241+
242+ } ) ( jQuery ) ;
0 commit comments