@@ -88,27 +88,27 @@ editor.getSession().setMode('ace/mode/javascript');
88
88
/* ------------------------------------------------------------
89
89
EVENT LISTENERS / SEND DATA TO SERVER
90
90
91
- EVENT NAMES: CLIENT FUNCTIONS:
92
- - connection Send: SocketIO built-in event
93
- - disconnect Send: SocketIO built-in event
94
- - loggedIn Send: handleUserLogin
95
- - editorChange Send: handleUserTyping
96
- Receive: handleEditorChange
97
- - playerListChange Receive: handlePlayerListChange
98
- - updateState Receive: handleUpdateState
99
- - turnChange Receive: handleTurnChange
100
- - changeCursor Send: handleChangeCursor
101
- Receive: handleNewCursorData
102
- - changeScroll Send: handleChangeScroll
103
- Receive: handleNewScrollData
104
- - createNewGist Receive: createNewGist
105
- - newGistLink Receive: handleNewGistLink
106
- Send: (sent after creating or forking)
91
+ EVENT NAMES: CLIENT FUNCTIONS:
92
+ - connection Send: SocketIO built-in event
93
+ - disconnect Send: SocketIO built-in event
94
+ - userLogin Send: handleUserLogin
95
+ - editorTextChange Send: handleLocalEditorTextChange
96
+ Receive: handleServerEditorTextChange
97
+ - playerListChange Receive: handlePlayerListChange
98
+ - updateState Receive: handleUpdateState
99
+ - turnChange Receive: handleTurnChange
100
+ - editorCursorChange Send: handleLocalEditorCursorChange
101
+ Receive: handleServerEditorCursorChange
102
+ - editorScrollChange Send: handleLocalEditorScrollChange
103
+ Receive: handleServerEditorScrollChange
104
+ - createNewGist Receive: handleCreateNewGist
105
+ - newGistLink Receive: handleNewGistLink
106
+ Send: (sent after creating or forking)
107
107
-------------------------------------------------------------- */
108
- editor . getSession ( ) . on ( 'change' , handleUserTyping ) ;
109
- editor . getSession ( ) . selection . on ( 'changeCursor ' , handleChangeCursor ) ;
110
- editor . getSession ( ) . on ( 'changeScrollLeft' , handleChangeScroll ) ;
111
- editor . getSession ( ) . on ( 'changeScrollTop' , handleChangeScroll ) ;
108
+ editor . getSession ( ) . on ( 'change' , handleLocalEditorTextChange ) ;
109
+ editor . getSession ( ) . selection . on ( 'editorCursorChange ' , handleLocalEditorCursorChange ) ;
110
+ editor . getSession ( ) . on ( 'changeScrollLeft' , handleLocalEditorScrollChange ) ;
111
+ editor . getSession ( ) . on ( 'changeScrollTop' , handleLocalEditorScrollChange ) ;
112
112
113
113
// When client connects to server,
114
114
socket . on ( 'connect' , function ( ) {
@@ -135,12 +135,12 @@ function handleUserLogin (userData) {
135
135
updateLoggedInView ( userData . login , userData . avatar_url ) ;
136
136
137
137
// Notify server that user logged in
138
- socket . emit ( 'loggedIn ' , { login : userData . login , avatar_url : userData . avatar_url } ) ;
138
+ socket . emit ( 'userLogin ' , { login : userData . login , avatar_url : userData . avatar_url } ) ;
139
139
}
140
140
141
141
// Send editorInputView data to server
142
- function handleUserTyping ( event ) {
143
- //console.log('handleUserTyping event! value: ');
142
+ function handleLocalEditorTextChange ( event ) {
143
+ //console.log('handleLocalEditorTextChange event! value: ');
144
144
//console.log(event);
145
145
146
146
//console.log('%c ' + editor.getValue(), 'color: green; font-weight: bold;');
@@ -149,7 +149,7 @@ function handleUserTyping (event) {
149
149
if ( socket . id === currentPlayerId ) {
150
150
//console.log('Sending data to server!')
151
151
// Send data to server
152
- socket . emit ( 'editorChange ' , editor . getValue ( ) ) ;
152
+ socket . emit ( 'editorTextChange ' , editor . getValue ( ) ) ;
153
153
}
154
154
}
155
155
@@ -176,8 +176,8 @@ function handleUserNameChange (event) {
176
176
}
177
177
178
178
// Send cursor and selection data to server
179
- function handleChangeCursor ( event ) {
180
- //console.log('changeCursor fired!');
179
+ function handleLocalEditorCursorChange ( event ) {
180
+ //console.log('editorCursorChange fired!');
181
181
//console.log('%c ' + event, 'color: green; font-weight: bold;');
182
182
183
183
// Cursor object:
@@ -187,16 +187,16 @@ function handleChangeCursor (event) {
187
187
// { end: {column, row}, start: {column, row} }
188
188
189
189
// Send to server:
190
- socket . emit ( 'changeCursor ' , { cursor : editor . getSession ( ) . selection . getCursor ( ) , range : editor . getSession ( ) . selection . getRange ( ) } ) ;
190
+ socket . emit ( 'editorCursorChange ' , { cursor : editor . getSession ( ) . selection . getCursor ( ) , range : editor . getSession ( ) . selection . getRange ( ) } ) ;
191
191
}
192
192
193
193
// Send scroll data to server
194
- function handleChangeScroll ( event ) {
195
- //console.log('changeScroll (left or top) fired!');
194
+ function handleLocalEditorScrollChange ( event ) {
195
+ //console.log('editorScrollChange (left or top) fired!');
196
196
//console.log('%c scrollLeft: ' + editor.getSession().getScrollLeft() + ', scrollTop: ' + editor.getSession().getScrollTop(), 'color: green; font-weight: bold;');
197
197
198
198
// Send to server:
199
- socket . emit ( 'changeScroll ' , { scrollLeft : editor . getSession ( ) . getScrollLeft ( ) , scrollTop : editor . getSession ( ) . getScrollTop ( ) } ) ;
199
+ socket . emit ( 'editorScrollChange ' , { scrollLeft : editor . getSession ( ) . getScrollLeft ( ) , scrollTop : editor . getSession ( ) . getScrollTop ( ) } ) ;
200
200
}
201
201
202
202
// TODO: Test 'input' event some more in different browsers!
@@ -205,25 +205,25 @@ function handleChangeScroll (event) {
205
205
/* -------------------------------------------------
206
206
EVENT LISTENERS / RECEIVE DATA FROM SERVER
207
207
---------------------------------------------------- */
208
- socket . on ( 'editorChange ' , handleEditorChange ) ;
209
- socket . on ( 'changeCursor ' , handleNewCursorData ) ;
210
- socket . on ( 'changeScroll ' , handleNewScrollData ) ;
208
+ socket . on ( 'editorTextChange ' , handleServerEditorTextChange ) ;
209
+ socket . on ( 'editorCursorChange ' , handleServerEditorCursorChange ) ;
210
+ socket . on ( 'editorScrollChange ' , handleServerEditorScrollChange ) ;
211
211
socket . on ( 'playerListChange' , handlePlayerListChange ) ;
212
212
socket . on ( 'updateState' , handleUpdateState ) ;
213
213
socket . on ( 'turnChange' , handleTurnChange ) ;
214
- socket . on ( 'createNewGist' , createNewGist ) ;
214
+ socket . on ( 'createNewGist' , handleCreateNewGist ) ;
215
215
socket . on ( 'newGistLink' , handleNewGistLink ) ;
216
216
217
217
// When receiving new editorInputView data from server
218
- function handleEditorChange ( data ) {
219
- //console.log('editorChange event received!');
218
+ function handleServerEditorTextChange ( data ) {
219
+ //console.log('editorTextChange event received!');
220
220
//console.log('%c ' + data, 'color: blue; font-weight: bold;');
221
221
222
222
updateEditorView ( data ) ;
223
223
}
224
224
225
225
// When receiving new cursor/selection data from server
226
- function handleNewCursorData ( data ) {
226
+ function handleServerEditorCursorChange ( data ) {
227
227
//console.log('%c cursorChange event received!', 'color: blue; font-weight: bold;');
228
228
//console.dir(data);
229
229
@@ -233,8 +233,8 @@ function handleNewCursorData (data) {
233
233
}
234
234
235
235
// When receiving new scroll data from server
236
- function handleNewScrollData ( data ) {
237
- //console.log('%c scrollChange event received!', 'color: blue; font-weight: bold;');
236
+ function handleServerEditorScrollChange ( data ) {
237
+ //console.log('%c editorScrollChange event received!', 'color: blue; font-weight: bold;');
238
238
//console.dir(data);
239
239
240
240
// Set Ace editor's scroll position to match
@@ -531,8 +531,8 @@ function updateCurrentGistView (gistData) {
531
531
GITHUB API FUNCTIONS
532
532
---------------------------------------------------- */
533
533
// Make a POST request via AJAX to create a Gist for the current user
534
- function createNewGist ( ) {
535
- console . log ( 'called createNewGist at ' + new Date ( ) . toString ( ) . substring ( 16 , 25 ) , 'color: red; font-weight: bold;' ) ;
534
+ function handleCreateNewGist ( ) {
535
+ console . log ( 'called handleCreateNewGist at ' + new Date ( ) . toString ( ) . substring ( 16 , 25 ) , 'color: red; font-weight: bold;' ) ;
536
536
// use currentAccessToken
537
537
// use https://developer.github.com/v3/gists/#create-a-gist
538
538
@@ -551,7 +551,7 @@ function createNewGist() {
551
551
552
552
postWithGitHubToken ( 'https://api.github.com/gists' , gistObject ) . then ( function ( responseText ) {
553
553
//console.log(responseText);
554
- console . log ( 'createNewGist : response received at ' + new Date ( ) . toString ( ) . substring ( 16 , 25 ) , 'color: red; font-weight: bold;' ) ;
554
+ console . log ( 'handleCreateNewGist : response received at ' + new Date ( ) . toString ( ) . substring ( 16 , 25 ) , 'color: red; font-weight: bold;' ) ;
555
555
console . dir ( gistObject ) ;
556
556
557
557
var gistObject = JSON . parse ( responseText ) ;
0 commit comments