Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Harmony: server and javascript improvements #211

Merged
merged 31 commits into from
Nov 9, 2020

Conversation

antirotor
Copy link
Member

@antirotor antirotor commented Oct 27, 2020

Changes

This PR changes how javascript functions are processed in Harmony and improves on socket server used for communication between python and Harmony.

Javascript changes

All code running inside Harmony is now seperated from Python code and reside in js folder in its own files. ESlint is configured there via node.js to help with development if needed. Just run npm install inside js directory to get everything set up. If your favorite IDE supports ESlint, it should pick up its configuration with all globals and style codes.

After avalon is installed in host, it will read AvalonHarmony.js and send it directly to Harmony.

AvalonHarmony is javascript namespace containing all functions called by Avalon API. Too add new function, just add it to AvalonHarmony namespace like:

AvalonHarmony.someNewFunction = function() {
      someNewFunctionality();
};

and call it from Python like:

from avalon.harmony.lib import send

send({"function", "AvalonHarmony.someNewFunction"})

you can also pass:

from pathlib import Path
from avalon.harmony.lib import send

js_file = Path("/some/path/to/some.js")
send({"script",  js_file.read_text()})

and that will pass whole script file to Harmony and evaluate it in global scope.

Server changes

Server/client now uses stricter protocol to handle communication. This was necessary because there was no precise control over data passed between server/client. Now, each message is prepended with 6 bytes:

| A | H | 0x00 | 0x00 | 0x00 | 0x00 | ...

First two bytes are magic bytes stands for Avalon Harmony. Next four bytes hold length of the message ... encoded as 32bit unsigned integer. This way we know how many bytes to read from the socket and if we need more or we need to parse multiple messages.

Related

Python code was changed to be more Python 3 like.

🏴 Related PR pending: ynput/OpenPype#666

mkolar and others added 27 commits September 15, 2020 18:09
@antirotor antirotor added the enhancement New feature or request label Oct 27, 2020
@antirotor antirotor requested a review from a team October 27, 2020 16:42
@antirotor antirotor self-assigned this Oct 27, 2020
@mkolar
Copy link
Member

mkolar commented Oct 28, 2020

I'm getting syntax error after opening harmony but can't see what is wrong with it to be honest.
image

@antirotor
Copy link
Member Author

I'm getting syntax error after opening harmony but can't see what is wrong with it to be honest.

problem is request.function vs request["function"]. Obviously some namespace clash again. Should be fixed now.

@mkolar mkolar merged commit b2de513 into 2.x/develop Nov 9, 2020
@mkolar mkolar deleted the feature/openHarmony-integration branch November 9, 2020 22:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants