Skip to content

Commit

Permalink
removed support for name message from admin and server. #28
Browse files Browse the repository at this point in the history
  • Loading branch information
quinkennedy committed Oct 29, 2012
1 parent ac8525f commit c4f6fde
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 78 deletions.
25 changes: 11 additions & 14 deletions examples/admin/js/wsevents.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ var clients = [];
var routes = [];

var handleMsg = function(json){
if (json.name){
handleNameMsg(json);
} else if (json.config){
if (json.config){
handleConfigMsg(json);
} else if (json.message){
handleMessageMsg(json);
Expand Down Expand Up @@ -91,16 +89,6 @@ var getCommItemSelector = function(a_bPublisher, a_sClientName, a_sRemoteAddress
type: a_sType});
};

var handleNameMsg = function(msg){
for(var i = 0; i < msg.name.length; i++){
var currClient = {name:msg.name[i].name, remoteAddress:msg.name[i].remoteAddress}
clients.push(currClient);
var clientMarkup = $(clientTemplate(currClient));
clientMarkup.find(".infobutton").click(clickInfo);
$("#client_list").append(clientMarkup);
};
};

var routeTemplate;
routeTemplate = Handlebars.compile(document.getElementById( 'route_handlebar' ).textContent);
var clientTemplate;
Expand Down Expand Up @@ -156,9 +144,18 @@ var handleConfigMsg = function(msg){
$("#"+idPart+" span").html(msg.config.description);
client.find(".clientnickname, .clientname").attr("title",msg.config.description);
}
break;
return;
}
}

//if we did not find a matching client, then add this one
var newClient = {name:msg.config.name, remoteAddress:msg.config.remoteAddress};
var clientMarkup = $(clientTemplate(newClient));
clientMarkup.find(".infobutton").click(clickInfo);
$("#client_list").append(clientMarkup);
clients.push(newClient);
//and then updated it with the additional info.
handleConfigMsg(msg);
};

var removeClient = function(client){
Expand Down
2 changes: 1 addition & 1 deletion examples/javascript_examples/spacebrew_chat/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
var myConfig = {
"config": {
"name": name,
"description": "This is an example of a signage system",
"description": "This is simple chat client",
"publish": {
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion node_persistent_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ var receivedMessage = function(data, flags){
* @return {boolean} True iff the message was a recognized type
*/
var handleMessage = function(json){
if (json.name || json.message || json.admin){
if (json.message || json.admin){
//do nothing
} else if (json.config){
handleConfigMessage(json);
Expand Down
65 changes: 3 additions & 62 deletions node_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ console.log("More info at http://www.spacebrew.cc");
*/
var buildUpdateMessagesForAdmin = function(){
var output = [];
//re-create the 'name' and 'config' messages
//re-create the 'config' messages
for(var i = 0, end = trustedClients.length; i < end; i++){
var currClient = trustedClients[i];
var currMsg = {name:[{name:currClient.name, remoteAddress:currClient.remoteAddress}]};
output.push(currMsg);
currMsg = {config:currClient.config};
var currMsg = {config:currClient.config};
output.push(currMsg);
}
//now re-create the 'route' messages
Expand Down Expand Up @@ -126,9 +124,7 @@ wss.on('connection', function(ws) {
}

try{
if (tMsg['name']) {
bValidMessage = handleNameMessage(connection, tMsg);
} else if (tMsg['config']) {
if (tMsg['config']) {
bValidMessage = handleConfigMessage(connection, tMsg);
} else if (tMsg['message']) {
bValidMessage = handleMessageMessage(connection, tMsg);
Expand Down Expand Up @@ -454,8 +450,6 @@ var handleConfigMessage = function(connection, tMsg){
console.log("client added");
bValidMessage = true;
printAllTrustedClients();
//and send the name to the admins
sendToAdmins({name:[{name:msgName, remoteAddress:msgAddress}]});
}

//now that we have the base data structure, we can update it to match the new
Expand Down Expand Up @@ -586,59 +580,6 @@ var removeRoutesInvolving = function(item, client){
}
};

/**
* Handles the initial 'name' message from Clients that is used to register them with
* the Server. Currently deprecated.
* @param {ws Connection Obj} connection The connection that the message came in on
* @param {json} tMsg The name message from the Client
* @return {boolean} True iff there does not exist a Client with that name
*/
var handleNameMessage = function(connection, tMsg){
return false;
//IGNORING FOR NOW, ONLY CONFIG MESSAGES ARE SUPPORTED
// //a connection is registering themselves
// //console.log(tMsg['name']);
// for (var index = 0; index < tMsg['name'].length; index++){
// var tVar = [tMsg['name'][index].name, connection.upgradeReq.headers.host, connection];
// //add the remote address to the message for the admins
// tMsg['name'][index].remoteAddress = connection.upgradeReq.headers.host;

// var existingClient = false;
// for(var i=0; i<trustedClients.length; i++) {
// //console.log("NAMES: "+ trustedClients[i]['name'] +" : "+ tVar[0]);
// //console.log("ADDRESS: "+ trustedClients[i]['remoteAddress'] +" : "+ tVar[1]);
// if (trustedClients[i]['name'] === tVar[0] && trustedClients[i]['remoteAddress'] === tVar[1]) {
// existingClient = true;
// console.log("client is already connected -- denying new connection");
// connection.close();
// }
// }
// if (existingClient === false) {
// //console.log("Logged new connection");
// var tClient = {
// "name": tVar[0],
// "remoteAddress": tVar[1],
// "description": "",
// "connection": connection,
// "publishers": {},
// "subscribers": {},
// "config":""
// };
// console.log("Client is new");

// trustedClients.push(tClient);
// console.log("client added");
// bValidMessage = true;
// }
// }

// console.log("Here are the current trustedClients "+trustedClients.length);

// for (var i=0; i<trustedClients.length; i++) {
// console.log(trustedClients[i]['name']);
// }
}

/**
* Checks to see if the specified publisher and subscriber are already routed together
* @param {Client Obj} pubClient The Client object from the trustedClients array that contains this publisher
Expand Down

0 comments on commit c4f6fde

Please sign in to comment.