Comparing version 0.1.5 to 0.1.6
@@ -67,2 +67,5 @@ ;(function() { | ||
// Reply callback map for this client. | ||
this.replyCallbacks = {}; | ||
// #### Extending Events | ||
@@ -134,2 +137,7 @@ // Extending events is done exactly like in Ampersand or Backbone, except with | ||
self[events[event]].apply(self, args); | ||
// Call the reply callback if there is one: | ||
if (typeof meta === 'object' && self.replyCallbacks.hasOwnProperty(meta.replyTo)) { | ||
self.replyCallbacks[meta.replyTo].apply(self, args); | ||
delete self.replyCallbacks[meta.replyTo]; | ||
} | ||
}; | ||
@@ -157,2 +165,7 @@ // ##### Events with Subtypes | ||
self[next].apply(self, args); | ||
// Call the reply callback if there is one: | ||
if (typeof meta === 'object' && self.replyCallbacks.hasOwnProperty(meta.replyTo)) { | ||
self.replyCallbacks[meta.replyTo].apply(self, args); | ||
delete self.replyCallbacks[meta.replyTo]; | ||
} | ||
} | ||
@@ -333,3 +346,3 @@ }); | ||
// Start a session. | ||
start: function() { | ||
start: function(callback) { | ||
var payload = { | ||
@@ -343,5 +356,9 @@ meta: this.parent.generateMeta({ | ||
this.parent.emit('client session event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// End a session. | ||
end: function() { | ||
end: function(callback) { | ||
var payload = { | ||
@@ -355,5 +372,9 @@ meta: this.parent.generateMeta({ | ||
this.parent.emit('client session event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Login to a session. | ||
login: function(data) { | ||
login: function(data, callback) { | ||
var payload = { | ||
@@ -367,5 +388,9 @@ meta: this.parent.generateMeta({ | ||
this.parent.emit('client session event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Logout of a session. | ||
logout: function(data) { | ||
logout: function(data, callback) { | ||
var payload = { | ||
@@ -379,2 +404,6 @@ meta: this.parent.generateMeta({ | ||
this.parent.emit('client session event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
} | ||
@@ -385,3 +414,3 @@ }, | ||
// Start a chat. | ||
start: function(data) { | ||
start: function(data, callback) { | ||
// Add any Client information to the data. Override with any explicitly | ||
@@ -400,5 +429,9 @@ // set properties. | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Join a chat room. | ||
join: function(data) { | ||
join: function(data, callback) { | ||
var payload = { | ||
@@ -412,5 +445,9 @@ meta: this.parent.generateMeta({ | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Leave a chat. | ||
leave: function(data) { | ||
leave: function(data, callback) { | ||
var payload = { | ||
@@ -424,5 +461,9 @@ meta: this.parent.generateMeta({ | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Send a chat message. | ||
message: function(data) { | ||
message: function(data, callback) { | ||
var payload = { | ||
@@ -436,5 +477,9 @@ meta: this.parent.generateMeta({ | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Request the latest chat cache. | ||
cache: function(data) { | ||
cache: function(data, callback) { | ||
var payload = { | ||
@@ -448,5 +493,9 @@ meta: this.parent.generateMeta({ | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Request to transfer chat. | ||
requestTransfer: function(data) { | ||
requestTransfer: function(data, callback) { | ||
// Add any Client information to the data. Override with any explicitly | ||
@@ -465,5 +514,9 @@ // set properties. | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Respond to transfer chat. | ||
respondToTransfer: function(data) { | ||
respondToTransfer: function(data, callback) { | ||
// Add any Client information to the data. Override with any explicitly | ||
@@ -482,5 +535,9 @@ // set properties. | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Request the active users. | ||
getActiveUsers: function(data) { | ||
getActiveUsers: function(data, callback) { | ||
// Add any Client information to the data. Override with any explicitly | ||
@@ -499,5 +556,9 @@ // set properties. | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Request message cache. | ||
getCacheMessages: function(data) { | ||
getCacheMessages: function(data, callback) { | ||
// Add any Client information to the data. Override with any explicitly | ||
@@ -516,5 +577,9 @@ // set properties. | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
}, | ||
// Request metadata cache. | ||
getCacheMetadata: function(data) { | ||
getCacheMetadata: function(data, callback) { | ||
// Add any Client information to the data. Override with any explicitly | ||
@@ -533,2 +598,6 @@ // set properties. | ||
this.parent.emit('client chat event', payload); | ||
if (typeof callback === 'function') { | ||
this.parent.replyCallbacks[payload.meta.id] = callback; | ||
} | ||
} | ||
@@ -535,0 +604,0 @@ }, |
{ | ||
"name": "help-fem", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "A Browserify/Node.js client module for the Help.com team's FEM.", | ||
@@ -5,0 +5,0 @@ "main": "help-fem.js", |
25215
624