Skip to content

Commit

Permalink
after some fumbling, initial pass at functional skimming and two-pass…
Browse files Browse the repository at this point in the history
… initial layout, along with new parts of barista client to deal with "secret" (non-relaying) querying; still needs some fine tuning, but technically fixes #16
  • Loading branch information
kltm committed Oct 8, 2014
1 parent 48ee33d commit 9934995
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 22 deletions.
77 changes: 61 additions & 16 deletions barista.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var ModelCubby = function(){
var cubby = {};

/*
* Function: drop
* Function: dropoff
*
* returns true if new, false if update
*
Expand All @@ -54,7 +54,7 @@ var ModelCubby = function(){
* Returns:
* boolean
*/
self.drop = function(model, namespace, key, value){
self.dropoff = function(model, namespace, key, value){

var ret = null;

Expand All @@ -75,6 +75,7 @@ var ModelCubby = function(){

// Add to data bundle.
cubby[model][namespace][key] = value;
//console.log('cubby dropoff: '+ key + ', ', value);

return ret;
};
Expand All @@ -86,6 +87,7 @@ var ModelCubby = function(){
var ret = {};

// Give non-empty answer only if defined.
console.log('data: ', cubby);
if( typeof(cubby[model]) !== 'undefined' &&
typeof(cubby[model][namespace]) !== 'undefined' ){
ret = cubby[model][namespace];
Expand Down Expand Up @@ -1011,23 +1013,66 @@ var BaristaLauncher = function(){
data = _mod_data_with_session_info(data);
socket.broadcast.emit('relay', data);

// Update cubby layout information when screen items
// are moving via telekinesis for logged-in users.
// Skim object location and update cubby layout
// information when screen items are moving via
// telekinesis by logged-in users.
//console.log('relay: ', data);
if( data['class'] === 'telekinesis' ){
var mid = data['model_id'];
var iid = data['item_id'];
var itop = data['top'];
var ileft = data['left'];
if( typeof(mid) !== 'undefined' &&
typeof(iid) !== 'undefined' &&
typeof(itop) !== 'undefined' &&
typeof(ileft) !== 'undefined' ){
cubby.drop(mid, 'layout', iid,
{'top': itop, 'left': ileft});
//console.log('cubby m: ', cubby.model_count());
//console.log('cubby ns: ', cubby.namespace_count(mid));
//console.log('cubby ks: ', cubby.key_count(mid, 'layout'));
var obs = data['objects'];
if( typeof(mid) !== 'undefined' &&
typeof(obs) === 'object' ){
each(obs, function(ob){
var iid = ob['item_id'];
var itop = ob['top'];
var ileft = ob['left'];
if( typeof(iid) !== 'undefined' &&
typeof(itop) !== 'undefined' &&
typeof(ileft) !== 'undefined' ){
cubby.dropoff(mid, 'layout', iid,
{'top': itop,
'left': ileft});
// console.log('cubby m: ',
// cubby.model_count());
// console.log('cubby ns: ',
// cubby.namespace_count(mid));
// console.log('cubby ks: ',
// cubby.key_count(mid, 'layout'));
}
});
}
}
}
});

//
socket.on('query', function(data){
//console.log('srv tele: ' + data);
monitor_messages = monitor_messages +1;

// TODO: Respond to client query.
// Pong it back.
//console.log('PROCESSING', socket_id);
//console.log('PROCESSING', socket);
// Send message back to just the sending client.
// TODO: I feel there has to be a better way of doing this.
if( sio.sockets.sockets[socket_id] ){

// Check that we have a good looking packet.
var dq = data['query'];
var mid = data['model_id'];
if( dq && mid ){

// Give the current layout information from cubby.
if( dq === 'layout' ){

// Inject response.
data['response'] = cubby.pickup(mid, 'layout');

// Send back.
sio.sockets.sockets[socket_id].emit('query', data);
console.log('respond to query from ' +
socket_id + ' with:', data);
}
}
}
Expand Down
32 changes: 29 additions & 3 deletions js/NoctuaEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ var MMEnvInit = function(in_model, in_relations, in_token){
// real node class elements.
_make_selector_source('.demo-window', '.konn');

});
});
}

// This is a very important core function. It's purpose is to
Expand Down Expand Up @@ -1592,11 +1592,10 @@ var MMEnvInit = function(in_model, in_relations, in_token){

// Update locations for all items in the "objects" list.
function _on_telekinesis_update(data){
//function _on_telekinesis_update(uid, iid, top, left){

if( data && data['objects'] ){
var objects = data['objects'];
each( objects, function(obj){
each(objects, function(obj){

var iid = obj['item_id'];
var top = obj['top'];
Expand All @@ -1621,6 +1620,29 @@ var MMEnvInit = function(in_model, in_relations, in_token){
}
}

// Jimmy into telekinesis format and trigger
// _on_telekinesis_update().
function _on_layout_response(data){

//console.log('_on_layout_response:', data);
if( data && data['response'] ){

// Prep layout info.
var tk_items = {'objects':[]};
each(data['response'], function(iid, tnl){
tk_items['objects'].push({
'item_id': iid,
'top': tnl['top'],
'left': tnl['left']
});
});

//
//console.log('tk_items:', tk_items);
_on_telekinesis_update(tk_items);
}
}

if( typeof(global_barista_location) === 'undefined' ){
alert('no setup for messaging--not gunna happen');
}else{
Expand All @@ -1632,7 +1654,11 @@ var MMEnvInit = function(in_model, in_relations, in_token){
barclient.register('message', 'c', _on_message_update);
barclient.register('clairvoyance', 'd', _on_clairvoyance_update);
barclient.register('telekinesis', 'e', _on_telekinesis_update);
barclient.register('query', 'f', _on_layout_response);
barclient.connect(ecore.get_id());

// TODO/BUG: Playing with barista queries.
barclient.query('query', {'query': 'layout'});
}

//
Expand Down
58 changes: 55 additions & 3 deletions static/bbopx.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ bbopx.barista.response.prototype.export_model = function(){
//// Let's try and communicate with the socket.io server for
//// messages and the like.
////
//// There are two makor categories: "relay" and "query". Relays are
//// for passing information on to other clients (e.g. "where I am");
//// queries are for asking barista information about what it might
//// know (e.g. "where is X").
////

if ( typeof bbopx == "undefined" ){ var bbopx = {}; }
if ( typeof bbopx.barista == "undefined" ){ bbopx.barista = {}; }
Expand All @@ -528,10 +533,11 @@ bbopx.barista.client = function(barista_location, token){
bbop.registry.call(this, ['connect',
'initialization',
//'disconnect',
'relay', // catch-all
'message',
'clairvoyance',
'telekinesis',
'relay']); // catch-all
'query']); // asking barista something for yourself
this._is_a = 'bbopx.barista.client';

var anchor = this;
Expand All @@ -542,10 +548,14 @@ bbopx.barista.client = function(barista_location, token){

// These are the non-internal ones that we know about.
var known_relay_classes = {
'relay': true,
// Specific forms of relay.
'message': true,
'clairvoyance': true,
'telekinesis': true,
'relay': true
'telekinesis': true
};
var known_query_classes = {
'query': true
};

var logger = new bbop.logger('barista client');
Expand Down Expand Up @@ -605,6 +615,27 @@ bbopx.barista.client = function(barista_location, token){
}
};

/*
* General structure for requesting information from Barista about
* things it might know.
* Always check that the comm is on.
* Always inject 'token' and 'model_id'.
*/
anchor.query = function(query_class, data){
if( ! anchor.okay() ){
ll('no good socket on location; did you connect()?');
}else{
ll('sending query: ('+ anchor.model_id +', '+ anchor.token() +')');

// Inject our data.
data['class'] = query_class;
data['model_id'] = anchor.model_id;
data['token'] = anchor.token();

anchor.socket.emit('query', data);
}
};

/*
* Required call before using messenger.
*/
Expand Down Expand Up @@ -706,6 +737,27 @@ bbopx.barista.client = function(barista_location, token){
}
}
});

// Setup to catch query events from things we'veasked
// barista.
anchor.socket.on('query', function(data){
data = _inject_data_with_client_info(data);

// Check to make sure it interests us.
if( _applys_to_us_p(data) ){

var dclass = data['class'];
if( ! dclass ){
ll('no query class found');
}else if( ! known_query_classes[dclass] ){
ll('unknown query class: ' + dclass);
}else{
// Run appropriate callbacks.
ll('apply "'+ dclass +'" callbacks');
anchor.apply_callbacks(dclass, [data]);
}
}
});
}
};

Expand Down

0 comments on commit 9934995

Please sign in to comment.