-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
736 lines (663 loc) · 25.4 KB
/
index.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
const ArgumentType = require("../../extension-support/argument-type");
const BlockType = require("../../extension-support/block-type");
const formatMessage = require("format-message");
// const io = require("socket.io-client"); // yarn add socket.io-client socket.io-client@2.2.0
const AdapterBaseClient = require("./codelab_adapter_base.js");
// 翻译
const FormHelp = {
en: "help",
"zh-cn": "帮助",
};
const FormWebUI = {
en: "open Adapter Web UI",
"zh-cn": "打开Adapter控制台",
};
const Form_is_adapter_running = {
en: "is Adapter running?",
"zh-cn": "Adapter 已开启?",
}
const Form_whenMessageReceive = {
en: "when I receive [content]",
"zh-cn": "当接收到 [content]",
}
const Form_whenAnyMessageReceive = {
en: "when I receive any message",
"zh-cn": "当接收到任何消息",
}
const Form_getComingMessage = {
en: "received message",
"zh-cn": "收到的消息",
}
const Form_getComingTapicMessage = {
en: "received [node_id] message",
"zh-cn": "收到[node_id]的消息",
}
const Form_sendMessageAndWait = {
en: "broadcast [content] and wait",
"zh-cn": "广播[content]并等待",
}
const Form_sendMessage = {
en: "broadcast [content]",
"zh-cn": "广播 [content]",
}
const Form_broadcastMessageAndWait_REPORTER = {
en: "broadcast [content] and wait",
"zh-cn": "广播[content]并等待",
}
const Form_control_extension = {
en: "[turn] [ext_name]",
"zh-cn": "[turn] [ext_name]",
}
const Form_is_extension_turned_on = {
en: "is [ext_name] turned on?",
"zh-cn": "[ext_name]已开启?",
}
const Form_control_node = {
en: "[turn] [node_name]",
"zh-cn": "[turn] [node_name]",
}
const Form_is_node_turned_on = {
en: "is [node_name] turned on?",
"zh-cn": "[node_name]已开启?",
}
const Form_whenTopicMessageReceive = {
en: "when I receive [node_id] [content]",
"zh-cn": "当接收到 [node_id] [content]",
}
const Form_whenAnyTopicMessageReceive = {
en: "when I receive [node_id] any message",
"zh-cn": "当接收到 [node_id] 任何消息",
}
const Form_sendTopicMessageAndWait = {
en: "broadcast [node_id] [content] and wait",
"zh-cn": "广播[node_id][content]并等待",
}
const Form_sendTopicMessage = {
en: "broadcast [node_id] [content]",
"zh-cn": "广播[node_id][content]",
}
const Form_sendTopicMessageAndWait_REPORTER = {
en: "broadcast [node_id] [content] and wait",
"zh-cn": "广播[node_id][content]并等待",
}
const Form_trust_adapter_host = {
en: "trust adapter host[adapter_host]",
"zh-cn": "信任[adapter_host]",
}
const FormSetEmitTimeout = {
en: "set wait timeout [emit_timeout]s",
"zh-cn": "设置等待超时时间[emit_timeout]秒",
};
/**
* Icon svg to be displayed at the left edge of each extension block, encoded as a data URI.
* @type {string}
*/
// eslint-disable-next-line max-len
const blockIconURI = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNC4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0i5Zu+5bGCXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgNDAgNDAiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDQwIDQwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPg0KCS5zdDB7ZmlsbDojRkZGRkZDO30NCgkuc3Qxe2ZpbGw6IzgyNkFFRTt9DQoJLnN0MntmaWxsOiNGRkZGRkY7fQ0KPC9zdHlsZT4NCjx0aXRsZT7mianlsZXmj5Lku7bphY3lm77orr7orqE8L3RpdGxlPg0KPGcgaWQ9Il8yLl9FSU0iPg0KCTxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik0zMy45NSwxMC4xNnYxNC41MmMwLDAuNDktMC4xNiwwLjktMC40OSwxLjIzYy0wLjMzLDAuMzMtMC43NCwwLjQ5LTEuMjMsMC40OUgyMS45Nw0KCQljLTAuNDEsMC0wLjc0LDAuMDgtMS4wNywwLjMzaC0wLjA4bDAsMGwtNS4xNywzLjYxdi0xLjcyYzAtMS4xNS0wLjk4LTIuMTMtMi4xMy0yLjEzSDcuNjljLTAuNDksMC0wLjktMC4xNi0xLjIzLTAuNDkNCgkJYy0wLjMzLTAuMzMtMC40OS0wLjc0LTAuNDktMS4yM1YxMC4xNmMwLTAuNDksMC4xNi0wLjksMC40OS0xLjIzQzYuNzksOC42LDcuMiw4LjQzLDcuNjksOC40M2gyNC41M2MwLjQ5LDAsMC45LDAuMTYsMS4yMywwLjQ5DQoJCUMzMy43OCw5LjI1LDMzLjk1LDkuNzQsMzMuOTUsMTAuMTZ6Ii8+DQoJPHBhdGggY2xhc3M9InN0MSIgZD0iTTMyLjIzLDYuNDZINy43N0M1LjcyLDYuNDYsNCw4LjEsNCwxMC4yNHYxNC41MmMwLDIuMDUsMS43MiwzLjc3LDMuNzcsMy43N2g1LjgzYzAuMDgsMCwwLjE2LDAuMDgsMC4xNiwwLjE2DQoJCWwwLDB2My45NGMwLDAuNDksMC40MSwwLjksMC45LDAuOWMwLjE2LDAsMC4zMywwLDAuNDEtMC4wOGw2Ljg5LTQuODRoMTAuMjZjMi4wNSwwLDMuNzctMS42NCwzLjc3LTMuNzdWMTAuMTYNCgkJQzM2LDguMSwzNC4yOCw2LjM4LDMyLjIzLDYuNDZMMzIuMjMsNi40NnoiLz4NCgk8cGF0aCBjbGFzcz0ic3QyIiBkPSJNMTguMDMsMTcuOTVjMCwxLjA3LDAuODIsMi4wNSwxLjk3LDIuMDVjMS4wNywwLDIuMDUtMC44MiwyLjA1LTEuOTdjMC0xLjA3LTAuODItMi4wNS0xLjk3LTIuMDUNCgkJYzAsMCwwLDAtMC4wOCwwQzE4LjkzLDE1Ljk4LDE4LjAzLDE2LjgsMTguMDMsMTcuOTV6IE0xMC42NSwxNy45NWMwLDEuMDcsMC44MiwyLjA1LDEuOTcsMi4wNWMxLjA3LDAsMi4wNS0wLjgyLDIuMDUtMS45Nw0KCQljMC0xLjA3LTAuODItMi4wNS0xLjk3LTIuMDVjMCwwLDAsMC0wLjA4LDBDMTEuNjMsMTUuOTgsMTAuNzMsMTYuOCwxMC42NSwxNy45NUwxMC42NSwxNy45NXogTTI1LjMzLDE3Ljk1DQoJCWMwLDEuMDcsMC44MiwyLjA1LDEuOTcsMi4wNWMxLjA3LDAsMi4wNS0wLjgyLDIuMDUtMS45N2MwLTEuMDctMC44Mi0yLjA1LTEuOTctMi4wNWMwLDAsMCwwLTAuMDgsMA0KCQlDMjYuMjQsMTUuOTgsMjUuMzMsMTYuOCwyNS4zMywxNy45NUwyNS4zMywxNy45NXoiLz4NCjwvZz4NCjwvc3ZnPg0K';
const menuIconURI = blockIconURI;
const NODE_ID = "eim";
const HELP_URL = "https://adapter.codelab.club/extension_guide/eim/";
// EIM: Everything Is Message
// EIM 与 webui client 的区别: EIM 不关心关于环境的信息
class EIMClient {
update_nodes_status(nodes_status) {
this.exts_statu = nodes_status["exts_status_and_info"];
this.nodes_statu = nodes_status["node_status_and_info"];
console.log("this.exts_statu ->", this.exts_statu);
}
node_statu_change_callback(extension_node_name, content) {
const status_checked_map = { start: true, stop: false };
if (extension_node_name.startsWith("extension_")) {
this.exts_statu[extension_node_name]["is_running"] =
status_checked_map[content];
console.log(`extension statu change to ${content}`);
}
if (extension_node_name.startsWith("node_")) {
this.nodes_statu[extension_node_name]["is_running"] =
status_checked_map[content];
console.log(`node statu change to ${content}`);
}
}
onAdapterPluginMessage(msg) {
this.adapter_node_content_hat = msg.message.payload.content; // todo topic
this.adapter_node_content_reporter = msg.message.payload.content;
this.node_id = msg.message.payload.node_id;
}
constructor(node_id, help_url, runtime) {
this._runtime = runtime;
this.NODE_ID = node_id;
this.HELP_URL = help_url;
// eim
this.exts_statu = {};
this.nodes_statu = {};
this.emit_timeout = 5000; //ms
this.adapter_base_client = new AdapterBaseClient(
null, // onConnect,
null, // onDisconnect,
null, // onMessage,
this.onAdapterPluginMessage.bind(this), // onAdapterPluginMessage,
this.update_nodes_status.bind(this), // update_nodes_status,
this.node_statu_change_callback.bind(this), // node_statu_change_callback,
null, // notify_callback,
null, // error_message_callback,
null, // update_adapter_status
100 ,//SendRateMax // EIM没有可以发送100条消息
runtime,
);
}
emit_with_messageid(NODE_ID, content){
return this.adapter_base_client.emit_with_messageid(NODE_ID, content, this.emit_timeout)
}
isTargetMessage(content) {
// 是逻辑判断
if (
this.adapter_node_content_hat &&
(content === this.adapter_node_content_hat || content === "_any")
) {
// 1/100秒后清除
setTimeout(() => {
this.adapter_node_content_hat = null; // 每次清空
}, 1); //ms, 1/1000s ,只有一个通道 可能会覆盖消息。
return true;
}
}
isTargetTopicMessage(targerNodeId, targetContent) {
if (
(targetContent === this.adapter_node_content_hat || targetContent === "_any") &&
targerNodeId === this.node_id
) {
setTimeout(() => {
this.adapter_node_content_hat = null; // 每次清空
this.node_id = null;
}, 1); //ms
return true;
}
}
formatExtension() {
// text value list
console.debug("formatExtension exts_statu -> ", this.exts_statu)
if (this.exts_statu && Object.keys(this.exts_statu).length) {
// window.extensions_statu = this.exts_statu;
let extensions = Object.keys(this.exts_statu).map((ext_name) => ({
text: ext_name,
value: ext_name,
}));
return extensions;
}
return [
{
text: "extension_python",
value: "extension_python",
},
];
}
formatNode() {
// text value list
if (this.nodes_statu && Object.keys(this.nodes_statu).length) {
let nodes = Object.keys(this.nodes_statu).map((node_name) => ({
text: node_name,
value: node_name,
}));
return nodes;
}
return [
{
text: "node_physical_blocks",
value: "node_physical_blocks",
},
];
}
}
class EIMBlocks {
constructor(runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
*/
this.eim_client = new EIMClient(NODE_ID, HELP_URL, runtime);
}
/**
* The key to load & store a target's test-related state.
* @type {string}
*/
static get STATE_KEY() {
return "Scratch.eim";
}
_setLocale() {
let now_locale = "";
switch (formatMessage.setup().locale) {
case "en":
now_locale = "en";
break;
case "zh-cn":
now_locale = "zh-cn";
break;
default:
now_locale = "zh-cn";
break;
}
return now_locale;
}
/**
* @returns {object} metadata for this extension and its blocks.
*/
getInfo() {
let the_locale = this._setLocale();
return {
id: NODE_ID,
name: "EIM 消息传递",
menuIconURI: menuIconURI,
blockIconURI: blockIconURI,
blocks: [
{
opcode: "open_help_url",
blockType: BlockType.COMMAND,
text: FormHelp[the_locale],
arguments: {},
},
//FormWebUI
{
opcode: "openWebUI",
blockType: BlockType.COMMAND,
text: FormWebUI[the_locale],
arguments: {},
},
{
opcode: "is_adapter_running",
blockType: BlockType.BOOLEAN,
text: Form_is_adapter_running[the_locale],
arguments: {
},
},
{
opcode: "set_emit_timeout",
blockType: BlockType.COMMAND,
text: FormSetEmitTimeout[the_locale],
arguments: {
emit_timeout: {
type: ArgumentType.NUMBER,
defaultValue:5.0,
},
},
},
{
opcode: "whenMessageReceive",
blockType: BlockType.HAT,
text: Form_whenMessageReceive[the_locale],
arguments: {
content: {
type: ArgumentType.STRING,
defaultValue: "hello",
},
},
},
{
opcode: "whenAnyMessageReceive",
blockType: BlockType.HAT,
text: Form_whenAnyMessageReceive[the_locale],
arguments: {},
},
{
opcode: "getComingMessage",
blockType: BlockType.REPORTER, // BOOLEAN, COMMAND
text: Form_getComingMessage[the_locale],
arguments: {},
},
// 优先推荐wait模式(同步)
{
opcode: "broadcastMessageAndWait",
blockType: BlockType.COMMAND,
text: Form_sendMessageAndWait[the_locale],
arguments: {
content: {
type: ArgumentType.STRING,
defaultValue: "hello",
},
},
},
{
opcode: "broadcastMessage",
blockType: BlockType.COMMAND,
text: Form_sendMessage[the_locale],
arguments: {
content: {
type: ArgumentType.STRING,
defaultValue: "hello",
},
},
},
{
opcode: "broadcastMessageAndWait_REPORTER",
blockType: BlockType.REPORTER,
text: Form_broadcastMessageAndWait_REPORTER[the_locale],
arguments: {
content: {
type: ArgumentType.STRING,
defaultValue: "hello",
},
},
},
{
opcode: "control_extension",
blockType: BlockType.COMMAND,
text: Form_control_extension[the_locale],
arguments: {
turn: {
type: ArgumentType.STRING,
defaultValue: "start",
menu: "turn",
},
ext_name: {
type: ArgumentType.STRING,
defaultValue: "extension_python",
menu: "exts_name",
},
},
},
{
opcode: "is_extension_turned_on",
blockType: BlockType.BOOLEAN,
text: Form_is_extension_turned_on[the_locale],
arguments: {
ext_name: {
type: ArgumentType.STRING,
defaultValue: "extension_python",
menu: "exts_name",
},
},
},
{
opcode: "control_node",
blockType: BlockType.COMMAND,
text: Form_control_node[the_locale],
arguments: {
turn: {
type: ArgumentType.STRING,
defaultValue: "start",
menu: "turn",
},
node_name: {
type: ArgumentType.STRING,
defaultValue: "node_physical_blocks",
menu: "nodes_name",
},
},
},
{
opcode: "is_node_turned_on",
blockType: BlockType.BOOLEAN,
text: Form_is_node_turned_on[the_locale],
arguments: {
node_name: {
type: ArgumentType.STRING,
defaultValue: "node_physical_blocks",
menu: "nodes_name",
},
},
},
{
opcode: "whenTopicMessageReceive",
blockType: BlockType.HAT,
text: Form_whenTopicMessageReceive[the_locale],
arguments: {
node_id: {
type: ArgumentType.STRING,
defaultValue: "eim/extension_python",
},
content: {
type: ArgumentType.STRING,
defaultValue: "3",
},
},
},
{
opcode: "whenAnyTopicMessageReceive",
blockType: BlockType.HAT,
text: Form_whenAnyTopicMessageReceive[the_locale],
arguments: {
node_id: {
type: ArgumentType.STRING,
defaultValue: "eim/extension_python",
},
},
},
{
opcode: "getComingTopicMessage",
blockType: BlockType.REPORTER, // BOOLEAN, COMMAND
text: Form_getComingTapicMessage[the_locale],
arguments: {
node_id: {
type: ArgumentType.STRING,
defaultValue: "eim/extension_python",
}
},
},
{
opcode: "broadcastTopicMessageAndWait",
blockType: BlockType.COMMAND,
text: Form_sendTopicMessageAndWait[the_locale],
arguments: {
node_id: {
type: ArgumentType.STRING,
defaultValue: "eim/extension_python",
},
content: {
type: ArgumentType.STRING,
defaultValue: "1+2",
},
},
},
{
opcode: "broadcastTopicMessage",
blockType: BlockType.COMMAND,
text: Form_sendTopicMessage[the_locale],
arguments: {
node_id: {
type: ArgumentType.STRING,
defaultValue: "eim/extension_python",
},
content: {
type: ArgumentType.STRING,
defaultValue: "1+2",
},
},
},
{
opcode: "broadcastTopicMessageAndWait_REPORTER",
blockType: BlockType.REPORTER,
text: Form_sendTopicMessageAndWait_REPORTER[the_locale],
arguments: {
node_id: {
type: ArgumentType.STRING,
defaultValue: "eim/extension_python",
},
content: {
type: ArgumentType.STRING,
defaultValue: "1+2",
},
},
},
{
opcode: "trust_adapter_host",
blockType: BlockType.COMMAND,
text: Form_trust_adapter_host[the_locale],
arguments: {
adapter_host: {
type: ArgumentType.STRING,
defaultValue: `${this.eim_client.adapter_base_client.adapterHost}`, //'https://raspberrypi.local:12358'
},
},
},
],
menus: {
// todo 动态
exts_name: "_formatExtension",
nodes_name: "_formatNode",
turn: {
acceptReporters: true,
items: ["start", "stop"],
},
},
};
}
_formatExtension() {
return this.eim_client.formatExtension();
}
_formatNode() {
return this.eim_client.formatNode();
}
/**
* Retrieve the block primitives implemented by this package.
* @return {object.<string, Function>} Mapping of opcode to Function.
*/
trust_adapter_host(args) {
const adapter_host = args.adapter_host;
window.open(`https://${adapter_host}:12358`);
}
open_help_url(args) {
window.open(HELP_URL);
}
openWebUI(args) {
let token = this.eim_client.adapter_base_client.token;
window.open(`https://codelab-adapter.codelab.club:12358/?adapter_token=${token}`);
}
is_adapter_running(args) {
return this.eim_client.adapter_base_client.connected;
}
// when receive
whenMessageReceive(args) {
const content = args.content;
return this.eim_client.isTargetMessage(content);
}
whenAnyMessageReceive(args) {
return this.eim_client.isTargetMessage("_any");
}
getComingMessage() {
let result = this.eim_client.adapter_node_content_reporter;
// 避免未定义
if (result){
if (typeof result == "string"){
return result
}
else{
return JSON.stringify(result)
}
} else{return ""}
}
getComingTopicMessage(args) {
const targetNodeId = args.node_id;
let result = this.eim_client.adapter_node_content_reporter;
// 避免未定义
if (targetNodeId === this.eim_client.node_id){
if (result){
if (typeof result == "string"){
return result
}
else{
return JSON.stringify(result)
}
}
}
return ""
}
// when receive
whenTopicMessageReceive(args) {
const targetNodeId = args.node_id;
const targetContent = args.content;
return this.eim_client.isTargetTopicMessage(
targetNodeId,
targetContent
);
}
whenAnyTopicMessageReceive(args) {
const targetNodeId = args.node_id;
return this.eim_client.isTargetTopicMessage(
targetNodeId,
"_any"
);
}
// broadcast message
// 使用广播的概念, 与scratch保持一致
broadcastMessage(args) {
const content = args.content;
this.eim_client.adapter_base_client.emit_without_messageid(NODE_ID, content);
return;
}
broadcastMessageAndWait(args) {
const content = args.content;
return this.eim_client.emit_with_messageid(NODE_ID, content);
}
broadcastMessageAndWait_REPORTER(args) {
const content = args.content;
return this.eim_client.emit_with_messageid(NODE_ID, content);
}
// broadcast message
// 使用广播的概念, 与scratch保持一致
broadcastTopicMessage(args) {
const node_id = args.node_id;
const content = args.content;
this.eim_client.adapter_base_client.emit_without_messageid(node_id, content);
return;
}
broadcastTopicMessageAndWait(args) {
// topic服务于消息功能, node_id承载业务逻辑(extension)
const node_id = args.node_id;
const content = args.content;
return this.eim_client.emit_with_messageid(node_id, content);
}
broadcastTopicMessageAndWait_REPORTER(args) {
// topic服务于消息功能, node_id承载业务逻辑(extension)
const node_id = args.node_id;
const content = args.content;
return this.eim_client.emit_with_messageid(node_id, content);
}
// wait/not wait
control_extension(args) {
const content = args.turn;
const ext_name = args.ext_name;
return this.eim_client.adapter_base_client.emit_with_messageid_for_control(
NODE_ID,
content,
ext_name,
"extension"
);
}
// todo 主动查询后端 使用rpc风格,有id的消息 和没有id的消息
is_extension_turned_on(args) {
const ext_name = args.ext_name;
const statu = this.eim_client.exts_statu[ext_name]["is_running"];
if (statu) {
return statu;
} else {
return false;
}
}
control_node(args) {
const content = args.turn;
const node_name = args.node_name;
return this.eim_client.adapter_base_client.emit_with_messageid_for_control(
NODE_ID,
content,
node_name,
"node"
);
}
// todo 主动查询后端 使用rpc风格,有id的消息 和没有id的消息
is_node_turned_on(args) {
const node_name = args.node_name;
const statu = this.eim_client.nodes_statu[node_name]["is_running"];
if (statu) {
return statu;
} else {
return false;
}
}
set_emit_timeout(args) {
const timeout = parseFloat(args.emit_timeout) * 1000;
this.eim_client.emit_timeout = timeout;
}
}
/*
注意安全问题: 赋予用户强大的能力,但提醒他们担心锤子砸伤脚
*/
module.exports = EIMBlocks;