-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbabascript.js
More file actions
59 lines (57 loc) · 1.66 KB
/
Copy pathbabascript.js
File metadata and controls
59 lines (57 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Baba = require('babascript')
Client = require('babascript-client')
module.exports = function(RED){
'use strict';
function BabascriptModule(n){
RED.nodes.createNode(this, n);
var node = this;
this.on("input", function(msg){
var key = msg.key || n.key
var name = n.name || msg.name || 'takumibaba'
if(key != undefined){
var baba = new Baba(name);
var options = msg.options || {}
baba.exec(key, options, function(result){
node.send({payload: result});
});
}
});
}
RED.nodes.registerType("babascript", BabascriptModule, {});
function BabascriptClientModule(n){
RED.nodes.createNode(this, n);
var node = this;
var name = n.name;
var client = null;
if(n.name != undefined){
console.log(n);
client = new Client(name);
client.on("get_task", function(task){
var getter = function(){
return client;
}
var p = {getClient: getter, data: task}
node.send({payload: p});
});
client.on("cancel_task", function(task){
var p = {getClient: getter, data: task}
node.send({payload: p});
});
console.log(client);
}
this.on('input', function(msg){
if(name !== msg.name){
client = new Client(n.name);
client.on("get_task", function(task){
var p = {getClient: getter, data: task}
node.send({payload: p});
});
client.on("cancel_task", function(task){
var p = {getClient: getter, data: task}
node.send({payload: p});
});
}
});
}
RED.nodes.registerType("babascriptclient", BabascriptClientModule, {});
}