Skip to content

Rename functions, closes issue #1 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions public/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,27 @@ editor.getSession().setMode('ace/mode/javascript');
/* ------------------------------------------------------------
EVENT LISTENERS / SEND DATA TO SERVER

EVENT NAMES: CLIENT FUNCTIONS:
- connection Send: SocketIO built-in event
- disconnect Send: SocketIO built-in event
- loggedIn Send: handleUserLogin
- editorChange Send: handleUserTyping
Receive: handleEditorChange
- playerListChange Receive: handlePlayerListChange
- updateState Receive: handleUpdateState
- turnChange Receive: handleTurnChange
- changeCursor Send: handleChangeCursor
Receive: handleNewCursorData
- changeScroll Send: handleChangeScroll
Receive: handleNewScrollData
- createNewGist Receive: createNewGist
- newGistLink Receive: handleNewGistLink
Send: (sent after creating or forking)
EVENT NAMES: CLIENT FUNCTIONS:
- connection Send: SocketIO built-in event
- disconnect Send: SocketIO built-in event
- userLogin Send: handleUserLogin
- editorTextChange Send: handleLocalEditorTextChange
Receive: handleServerEditorTextChange
- playerListChange Receive: handlePlayerListChange
- updateState Receive: handleUpdateState
- turnChange Receive: handleTurnChange
- editorCursorChange Send: handleLocalEditorCursorChange
Receive: handleServerEditorCursorChange
- editorScrollChange Send: handleLocalEditorScrollChange
Receive: handleServerEditorScrollChange
- createNewGist Receive: handleCreateNewGist
- newGistLink Receive: handleNewGistLink
Send: (sent after creating or forking)
-------------------------------------------------------------- */
editor.getSession().on('change', handleUserTyping);
editor.getSession().selection.on('changeCursor', handleChangeCursor);
editor.getSession().on('changeScrollLeft', handleChangeScroll);
editor.getSession().on('changeScrollTop', handleChangeScroll);
editor.getSession().on('change', handleLocalEditorTextChange);
editor.getSession().selection.on('editorCursorChange', handleLocalEditorCursorChange);
editor.getSession().on('changeScrollLeft', handleLocalEditorScrollChange);
editor.getSession().on('changeScrollTop', handleLocalEditorScrollChange);

// When client connects to server,
socket.on('connect', function(){
Expand All @@ -135,12 +135,12 @@ function handleUserLogin (userData) {
updateLoggedInView(userData.login, userData.avatar_url);

// Notify server that user logged in
socket.emit('loggedIn', {login: userData.login, avatar_url: userData.avatar_url});
socket.emit('userLogin', {login: userData.login, avatar_url: userData.avatar_url});
}

// Send editorInputView data to server
function handleUserTyping (event) {
//console.log('handleUserTyping event! value: ');
function handleLocalEditorTextChange (event) {
//console.log('handleLocalEditorTextChange event! value: ');
//console.log(event);

//console.log('%c ' + editor.getValue(), 'color: green; font-weight: bold;');
Expand All @@ -149,7 +149,7 @@ function handleUserTyping (event) {
if (socket.id === currentPlayerId) {
//console.log('Sending data to server!')
// Send data to server
socket.emit( 'editorChange', editor.getValue() );
socket.emit( 'editorTextChange', editor.getValue() );
}
}

Expand All @@ -176,8 +176,8 @@ function handleUserNameChange (event) {
}

// Send cursor and selection data to server
function handleChangeCursor (event) {
//console.log('changeCursor fired!');
function handleLocalEditorCursorChange (event) {
//console.log('editorCursorChange fired!');
//console.log('%c ' + event, 'color: green; font-weight: bold;');

// Cursor object:
Expand All @@ -187,16 +187,16 @@ function handleChangeCursor (event) {
// { end: {column, row}, start: {column, row} }

// Send to server:
socket.emit( 'changeCursor', { cursor: editor.getSession().selection.getCursor(), range: editor.getSession().selection.getRange() } );
socket.emit( 'editorCursorChange', { cursor: editor.getSession().selection.getCursor(), range: editor.getSession().selection.getRange() } );
}

// Send scroll data to server
function handleChangeScroll (event) {
//console.log('changeScroll (left or top) fired!');
function handleLocalEditorScrollChange (event) {
//console.log('editorScrollChange (left or top) fired!');
//console.log('%c scrollLeft: ' + editor.getSession().getScrollLeft() + ', scrollTop: ' + editor.getSession().getScrollTop(), 'color: green; font-weight: bold;');

// Send to server:
socket.emit('changeScroll', { scrollLeft: editor.getSession().getScrollLeft(), scrollTop: editor.getSession().getScrollTop() });
socket.emit('editorScrollChange', { scrollLeft: editor.getSession().getScrollLeft(), scrollTop: editor.getSession().getScrollTop() });
}

// TODO: Test 'input' event some more in different browsers!
Expand All @@ -205,25 +205,25 @@ function handleChangeScroll (event) {
/* -------------------------------------------------
EVENT LISTENERS / RECEIVE DATA FROM SERVER
---------------------------------------------------- */
socket.on('editorChange', handleEditorChange);
socket.on('changeCursor', handleNewCursorData);
socket.on('changeScroll', handleNewScrollData);
socket.on('editorTextChange', handleServerEditorTextChange);
socket.on('editorCursorChange', handleServerEditorCursorChange);
socket.on('editorScrollChange', handleServerEditorScrollChange);
socket.on('playerListChange', handlePlayerListChange);
socket.on('updateState', handleUpdateState);
socket.on('turnChange', handleTurnChange);
socket.on('createNewGist', createNewGist);
socket.on('createNewGist', handleCreateNewGist);
socket.on('newGistLink', handleNewGistLink);

// When receiving new editorInputView data from server
function handleEditorChange (data) {
//console.log('editorChange event received!');
function handleServerEditorTextChange (data) {
//console.log('editorTextChange event received!');
//console.log('%c ' + data, 'color: blue; font-weight: bold;');

updateEditorView(data);
}

// When receiving new cursor/selection data from server
function handleNewCursorData (data) {
function handleServerEditorCursorChange (data) {
//console.log('%c cursorChange event received!', 'color: blue; font-weight: bold;');
//console.dir(data);

Expand All @@ -233,8 +233,8 @@ function handleNewCursorData (data) {
}

// When receiving new scroll data from server
function handleNewScrollData (data) {
//console.log('%c scrollChange event received!', 'color: blue; font-weight: bold;');
function handleServerEditorScrollChange (data) {
//console.log('%c editorScrollChange event received!', 'color: blue; font-weight: bold;');
//console.dir(data);

// Set Ace editor's scroll position to match
Expand Down Expand Up @@ -531,8 +531,8 @@ function updateCurrentGistView (gistData) {
GITHUB API FUNCTIONS
---------------------------------------------------- */
// Make a POST request via AJAX to create a Gist for the current user
function createNewGist() {
console.log('called createNewGist at ' + new Date().toString().substring(16,25), 'color: red; font-weight: bold;');
function handleCreateNewGist() {
console.log('called handleCreateNewGist at ' + new Date().toString().substring(16,25), 'color: red; font-weight: bold;');
// use currentAccessToken
// use https://developer.github.com/v3/gists/#create-a-gist

Expand All @@ -551,7 +551,7 @@ function createNewGist() {

postWithGitHubToken('https://api.github.com/gists', gistObject).then(function(responseText){
//console.log(responseText);
console.log('createNewGist: response received at ' + new Date().toString().substring(16,25), 'color: red; font-weight: bold;');
console.log('handleCreateNewGist: response received at ' + new Date().toString().substring(16,25), 'color: red; font-weight: bold;');
console.dir(gistObject);

var gistObject = JSON.parse(responseText);
Expand Down
48 changes: 24 additions & 24 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ server.listen(port, function() {

/* ------------------------------------------------------------
EVENT NAMES: SERVER FUNCTIONS:
- loggedIn io.emit: playerListChange
socket.emit: editorChange, changeScroll, changeCursor, turnChange
- userLogin io.emit: playerListChange
socket.emit: editorTextChange, editorScrollChange, editorCursorChange, turnChange
- disconnect Broadcast: playerListChange
- editorChange Broadcast: editorChange
- changeCursor Broadcast: changeCursor
- changeScroll Broadcast: changeScroll
- editorTextChange Broadcast: editorTextChange
- editorCursorChange Broadcast: editorCursorChange
- editorScrollChange Broadcast: editorScrollChange
- updateState Broadcast: updateState
- turnChange Broadcast: turnChange
- createNewGist Broadcast: createNewGist
Expand Down Expand Up @@ -102,7 +102,7 @@ io.on('connection', function (socket) {
//console.log('\t\t playerList.length: ' + playerList.length);

// When a user logs in,
socket.on('loggedIn', function (userData) {
socket.on('userLogin', function (userData) {
console.log('\n* * * * # # # # User logged in! # # # # * * * * *');
console.log('\t\t > > > ' + userData.login + ' < < <\n');
//console.log('\t\t playerList.length: ' + playerList.length);
Expand All @@ -114,12 +114,12 @@ io.on('connection', function (socket) {
playerList.push(socket.id);

// Send current state of the text editor to the new client, to initialize!
socket.emit('editorChange', editorContent);
socket.emit('editorTextChange', editorContent);
if (editorScroll != null) {
socket.emit('changeScroll', editorScroll);
socket.emit('editorScrollChange', editorScroll);
}
if (editorCursorAndSelection != null) {
socket.emit('changeCursor', editorCursorAndSelection);
socket.emit('editorCursorChange', editorCursorAndSelection);
}

// Initialize the turn (and timer) with first connected user
Expand All @@ -137,7 +137,7 @@ io.on('connection', function (socket) {
// Broadcast updated playerList to ALL clients
io.emit('playerListChange', playerData);

console.log('\non("loggedIn") -- turnData broadcasted!\n');
console.log('\non("userLogin") -- turnData broadcasted!\n');
//console.log( getTurnData() );

//console.log(' ! ! ! ! ! ! player data and list ! ! ! ! ! !');
Expand Down Expand Up @@ -204,10 +204,10 @@ io.on('connection', function (socket) {
}
});

// When "editorChange" event received, update editor state and broadcast it back out
socket.on('editorChange', function (data) {
// When "editorTextChange" event received, update editor state and broadcast it back out
socket.on('editorTextChange', function (data) {

//console.log('editorChange event received!');
//console.log('editorTextChange event received!');
//console.log(data);

// Double check that this user is allowed to type (in case of client-side tampering with the JS!)
Expand All @@ -216,17 +216,17 @@ io.on('connection', function (socket) {
editorContent = data;

// Broadcast updated editor content to other clients
socket.broadcast.emit('editorChange', editorContent);
socket.broadcast.emit('editorTextChange', editorContent);

//console.log('Broadcasting editorContent to other clients!');
}

});

// When "changeCursor" event received, update editor state and broadcast it back out
socket.on('changeCursor', function (data) {
// When "editorCursorChange" event received, update editor state and broadcast it back out
socket.on('editorCursorChange', function (data) {

//console.log('changeCursor event received!');
//console.log('editorCursorChange event received!');
//console.log(data);

// Double check that this user is allowed to broadcast (in case of client-side tampering with the JS!)
Expand All @@ -235,17 +235,17 @@ io.on('connection', function (socket) {
editorCursorAndSelection = data;

// Broadcast data to other clients
socket.broadcast.emit('changeCursor', editorCursorAndSelection);
socket.broadcast.emit('editorCursorChange', editorCursorAndSelection);

//console.log('Broadcasting changeCursor to other clients!');
//console.log('Broadcasting editorCursorChange to other clients!');
}

});

// When "changeScroll" event received, update editor state and broadcast it back out
socket.on('changeScroll', function (data) {
// When "editorScrollChange" event received, update editor state and broadcast it back out
socket.on('editorScrollChange', function (data) {

//console.log('changeScroll event received!');
//console.log('editorScrollChange event received!');
//console.log(data);

// Double check that this user is allowed to broadcast (in case of client-side tampering with the JS!)
Expand All @@ -254,9 +254,9 @@ io.on('connection', function (socket) {
editorScroll = data;

// Broadcast data to other clients
socket.broadcast.emit('changeScroll', editorScroll);
socket.broadcast.emit('editorScrollChange', editorScroll);

//console.log('Broadcasting changeScroll to other clients!');
//console.log('Broadcasting editorScrollChange to other clients!');
}

});
Expand Down