UNPKG

933 BJavaScriptView Raw
1var eve = require('../../index');
2
3function RequestAgent(id) {
4 // execute super constructor
5 eve.Agent.call(this, id);
6
7 // extend the agent with support for requests
8 this.extend('request');
9 // alternatively, the request module can be loaded in a separate namespace
10 // instead of extending the agent itself:
11 // this.request = this.loadModule('request');
12 // this.request.request(...)
13
14 // connect to all transports provided by the system
15 this.connect(eve.system.transports.getAll());
16}
17
18// extend the eve.Agent prototype
19RequestAgent.prototype = Object.create(eve.Agent.prototype);
20RequestAgent.prototype.constructor = RequestAgent;
21
22// implement the receive method
23RequestAgent.prototype.receive = function (from, message) {
24 console.log(from + ' said: ' + message);
25
26 // return value is send back as reply in case of a request
27 return 'Hi ' + from + ', nice to meet you!';
28};
29
30module.exports = RequestAgent;