postal.js/example/node/client/js/models/wiretap-model.js
2012-04-23 01:15:34 -04:00

40 lines
773 B
JavaScript

define( [
'backbone',
'postal'
],
function ( Backbone, postal ) {
"use strict";
var RawMessage = Backbone.Model.extend({
defaults: {
text: ""
}
});
return Backbone.Collection.extend( {
model: RawMessage,
initialize : function () {
var self = this;
postal.addWireTap(function( data, envelope ){
var text = "";
try {
text = JSON.stringify( envelope );
}
catch ( exception ) {
try {
var env = _.extend( {}, envelope );
delete env.data;
text = JSON.stringify( env ) + "\n\t" + "JSON.stringify Error: " + exception.message;
}
catch ( ex ) {
text = "Unable to parse data to JSON: " + exception;
}
}
self.add({ text: text });
});
}
} );
} );