1 | var eve = require('../../index');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function HelloAgent(id) {
|
10 |
|
11 | eve.Agent.call(this, id);
|
12 |
|
13 |
|
14 | this.connect(eve.system.transports.getAll());
|
15 | }
|
16 |
|
17 |
|
18 | HelloAgent.prototype = Object.create(eve.Agent.prototype);
|
19 | HelloAgent.prototype.constructor = HelloAgent;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | HelloAgent.prototype.sayHello = function(to) {
|
26 | this.send(to, 'Hello ' + to + '!').done();
|
27 | };
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | HelloAgent.prototype.receive = function(from, message) {
|
36 | console.log(from + ' said: ' + JSON.stringify(message));
|
37 |
|
38 | if (message.indexOf('Hello') === 0) {
|
39 |
|
40 | this.send(from, 'Hi ' + from + ', nice to meet you!');
|
41 | }
|
42 | };
|
43 |
|
44 | module.exports = HelloAgent;
|