Skip to content

Commit

Permalink
(bluefox) implement disk mirror (tested on windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Oct 2, 2019
1 parent 3260c7f commit da2ae4d
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 124 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ And then call "npm run build".
- ...

## Changelog
### 4.2.0 (2019-10-02)
* (bluefox) implement inter-script communication.

### 4.1.17 (2019-08-xx)
* (bluefox) Optimization: do not make useless iterations
* (bluefox) Allow to make requests to sites with self/signed certificates
Expand Down
18 changes: 9 additions & 9 deletions docs/en/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -1302,16 +1302,18 @@ It is not a function. It is a variable with javascript instance, that is visible
### messageTo
```
messageTo({instance: 'instance', script: 'scriptName', message: 'messageName'}, data, {timeout: 1000}, (err, result) =>
messageTo({instance: 'instance', script: 'script.js.common.scriptName', message: 'messageName'}, data, {timeout: 1000}, result =>
console.log(JSON.stringify(result)));
```
Sends via the message bus the message to some other script. Or even in the same script.
Sends via the "message bus" the message to some other script. Or even to some handler in the same script.
Timeout for callback is 5 seconds by default.
The target could be shorted to:
```
messageTo('messageName', data, (err, result) =>
messageTo('messageName', data, result =>
console.log(JSON.stringify(result)));
```
Expand All @@ -1321,24 +1323,22 @@ Callback and options are optional and timeout is by default 5000 milliseconds (i
messageTo('messageName', dataWithNoResponse);
```
***Not implemented yet***
### onMessage
```
onMessage('messageName', (data, callback) => {console.log(data); callback(null, Date.now())});
onMessage('messageName', (data, callback) => {console.log('Received data: ' + data); callback(null, Date.now())});
```
Subscribes on message bus and delivers response via callback.
The response from script which sends response as first will be accepted as answer, all other answers will be ignored.
***Not implemented yet***
### onMessageUnregister
```
const id = onMessage('messageName', (data, callback) => {console.log(data); callback(Date.now())});

// unsubscribe
// unsubscribe specific handler
onMessageUnregister(id);
// or unsubscribe by name
onMessageUnregister('messageName');
```
Unsubscribes from this message.
Expand Down
28 changes: 4 additions & 24 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"common": {
"name": "javascript",
"version": "4.1.16",
"version": "4.2.0",
"title": "Script Engine",
"titleLang": {
"en": "Script Engine",
Expand All @@ -22,6 +22,9 @@
"AlCalzone"
],
"news": {
"4.2.0": {

},
"4.1.17": {
"en": "Optimization: do not make useless iterations\nAllow to make requests to sites with self/signed certificates",
"de": "Optimierung: Machen Sie keine nutzlosen Iterationen\nAnfragen an Sites mit selbst signierten Zertifikaten zulassen",
Expand Down Expand Up @@ -118,29 +121,6 @@
"pl": "naprawia niechciane zmiany w ostatniej wersji",
"zh-cn": "修复了上一版本中不需要的更改"
},
"4.0.11": {
"en": "getBinaryState/setBinaryState were added",
"de": "getBinaryState/setBinaryState wurden hinzugefügt",
"ru": "getBinaryState/setBinaryState были добавлены",
"pt": "getBinaryState/setBinaryState foram adicionados",
"nl": "getBinaryState/setBinaryState zijn toegevoegd",
"fr": "getBinaryState/setBinaryState ont été ajoutés",
"it": "getBinaryState/setBinaryState sono stati aggiunti",
"es": "Se agregaron getBinaryState/setBinaryState",
"pl": "getBinaryState/setBinaryState zostały dodane",
"zh-cn": "添加了getBinaryState/setBinaryState"
},
"4.0.7": {
"en": "Material GUI",
"de": "Material GUI",
"ru": "Material GUI",
"pt": "Material GUI",
"nl": "Material GUI",
"fr": "Material GUI",
"it": "Material GUI",
"es": "Material GUI",
"pl": "Material GUI"
},
"3.7.0": {
"en": "Used VM2 as sandbox. The script errors will be caught.\nrefactoring: split into many modules",
"de": "Verwendete VM2 als Sandbox. Die Skriptfehler werden abgefangen.\nRefactoring: Aufteilung in viele Module",
Expand Down
42 changes: 30 additions & 12 deletions lib/javascript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import child_process = require("child_process");
type EmptyCallback = () => void;
type ErrorCallback = (err?: string) => void;
type GenericCallback<T> = (err: string | null, result?: T) => void;
type SimpleCallback<T> = (result?: T) => void;

// tslint:disable:no-namespace
declare global {
Expand Down Expand Up @@ -144,6 +145,8 @@ declare global {
message: string; // message name (required)
}

type MessageSubscribeID = number;

interface BaseObject {
/** The ID of this object */
_id?: string;
Expand Down Expand Up @@ -545,17 +548,17 @@ declare global {
*/
function log(message: string, severity?: iobJS.LogLevel): void;

// TODO: Do we need this?
// namespace console {
// /** log message with debug level */
// function debug(message: string): void;
// /** log message with info level (default output level for all adapters) */
// function info(message: string): void;
// /** log message with warning severity */
// function warn(message: string): void;
// /** log message with error severity */
// function error(message: string): void;
// }
// console functions
namespace console {
/** log message with debug level */
function debug(message: string): void;
/** log message with info level (default output level for all adapters) */
function info(message: string): void;
/** log message with warning severity */
function warn(message: string): void;
/** log message with error severity */
function error(message: string): void;
}

/**
* Executes a system command
Expand Down Expand Up @@ -886,7 +889,22 @@ declare global {
* @param data Any data, that should be sent to message bus
* @param options Actually only {timeout: X} is supported as option
* @param callback Callback to get the result from other script
* @return ID of the subscription. It could be used for un-subscribe.
*/
function messageTo(target: iobJS.TargetObject | string, data: any, options?: any, callback?: SimpleCallback<any>): iobJS.MessageSubscribeID;

/**
* Process message from other script.
* @param message Message name
* @param callback Callback to send the result to other script
*/
function onMessage(message: string, callback?: SimpleCallback<any>);

/**
* Process message from other script.
* @param id Message subscription id from onMessage or by message name
* @return true if subscription exists and was deleted.
*/
function messageTo(target: iobJS.TargetObject | string, data: any, options?: any, callback?: GenericCallback<any>): number;
function onMessageUnregister(id: iobJS.MessageSubscribeID | string): boolean;

}
Loading

0 comments on commit da2ae4d

Please sign in to comment.