-
Notifications
You must be signed in to change notification settings - Fork 129
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
BOT-296/Server Modules #313
Conversation
…nto BOT-296/socket_io_client
…dating require cache.
…l value or undefined.
…ocator internally.
what about @simonbrowndotje's Structurizer, i believe its free for open source projects? or as step 1 just draw it (but dont' let S Brown see you 👁 ) |
} | ||
|
||
module.exports = function(rooms, connectedClients) { | ||
return new Disconnector(rooms, connectedClients); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you aren't retaining any state you don't reallly need to new these up.
If you want to keep and treat them like classes, you should probably use classes 👻
module.exports = class Disconnector {
disconnectRoom(roomName) {
this._anInternalMethod()
}
_anInternalMethod() {
}
}
and then the usage convention is
const Disconnector = require('./disconnector')
const disconnector = new Disconnector()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah cool, I figured I'd learn something in the PR 😄
var roomsClientIsIn = Object.keys(clientsAndRooms[clientId]); | ||
|
||
for(var i = 0; i < roomsClientIsIn.length; i++) { | ||
emitter.to(roomsClientIsIn[i]).emit('direction', direction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks a little confusing, the room ids are keys in clientsAndRooms[clientId]
?
Also because we're in JS
land we can start dropping fori
loops in favour of .map/.forEach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
roomsClientIsIn
are the keys for the rooms that a given client belongs too. Yes this is confusing, I'll look into making this easier to read 👍
I'm going to make some changes as recommended by @ouchadam and will reopen after 😄 |
reopened = looks for diagrams... |
Adam has spoken, down with vars! |
happy to ship after that! |
Problem
A majority, if not all, of the
Server
logic is stored in a single file. This made testing the logic difficult because certain scenarios had to be built from a sequence of user actions.Solution
Split the
Server
into testable modules that use mocks for all dependencies.Router
determines whether a given client, human or bot, is able to connect to the server. A human client is passed off to theBotLocator
. Conversely, a bot is granted immediate access.BotLocator
finds and assigns a human to a bot if it is not already attached to another bot for a given room.Mover
sends a direction to all rooms that the given client belongs. In the case of a human, this will be the bot room directly.ServerCreator
handles the creation of the server and mainly passes off to collaborators given certain events.Server
entry point for node server, just used to create a default server using theServerCreator
.ClientType
js version of an enum that is used by the router to properly encapsulate theClientType
that is passed through thesocket.query
.Observer
to notify tests in scenarios where the ordinary socket lifecycle reporting cannot be used i.e. disconnection.Additional changes
this
everywhere.mocha.expect
BDD style assertions.