AnthonyMusgrove / Emby-ScripterX

Run custom external application or script (batch/bash/powershell/php/python/node.js/custom) on various events within the Emby Server.
https://emby-scripterx.com
76 stars 6 forks source link

Details on JavaScript env for Packages #29

Closed Slugger closed 4 years ago

Slugger commented 4 years ago

Is your feature request related to a problem? Please describe. Looking for details on the JavaScript engine/env available for Packages. Safe to assume it's Node.js under the hood? What access to the system do we have? Does our js run with the same access rights as the Emby server process? For example, if I wanted to go querying the user's file system, can I do that? Can I spawn other processes? Or are we running in some kind of restricted sandbox? If so, what are the restrictions?

I see there's a ScripterX namespace with an http client, for example. Is this for convenience or are we prohibited from doing our own http calls use node.js (again, assuming it's node.js under the hood)?

What about access to the Emby api from within this javascript env? Or are we just to make raw http calls? Would be nice if we could access the api thru this ScripterX object.

Describe the solution you'd like

Describe alternatives you've considered n/a

Additional context As you might guess, I'm in the early stages of a project of my own and integrating with ScripterX seems like it's going to save me a lot of work, especially this Packages idea. Just trying to get as much info about this env before I decide to go with developing a Package vs. just installing a series of actions for the various events.

AnthonyMusgrove commented 4 years ago

G'day again mate, these are great questions, and I'm so happy to be able to answer them. So far:

At the moment, under the hood the Javascript engine is ES5 and partially ES6 compatible. It's using the C# Jint library, you can check it out here: Jint Library

I'm continually watching for the release of EdgeJS with dotnetcore and I'll be integrating it very thoroughly!

Absolutely. I can also integrate FileIO functionality into the ScripterX object, which is basically a direct-line access to the exposed CLR from the plugin, I call them Contexts, and I add functionality to the exposed CLR where I see needed, however because it is only new, I know there is far more that can be integrated, and I'd love some suggestions so I can get them in there :)

Absolutely for convenience. Emby has an exposed IHttpClient that I integrate with for web get, post, etc. I wrap this into a context called PackageContext_WebClient, and expose an instance of it via the ScripterX context called Web. So essentially Web.Get/Web.Post are simply c# functions on a c# object that handle the underlying IHttpClient.

The email context (ScripterX.Email) is also a wrapper called PackageContext_Email, and exposed as ScripterX.Email, and utilises MailKit/MimeKit for its underlying functionality, which is pretty neat.

You could absolutely make calls to the Emby API using the Web.Post functionality, however I love this idea, and we should make it seamless. I think possibly another context for example PackageContext_EmbyAPI, expose it as ScripterX.EmbyAPI and include direct functionality to the API - this is a fantastic idea and I think we should integrate this!

"As you might guess, I'm in the early stages of a project of my own and integrating with ScripterX seems like it's going to save me a lot of work, especially this Packages idea. Just trying to get as much info about this env before I decide to go with developing a Package vs. just installing a series of actions for the various events."

I absolutely love that you have found a use for my plugin, I enjoy working on it thoroughly and if I can be of any help whatsoever to making your project easier to integrate into the plugin and emby, etc I am all ears, and I am more than happy to help. Thank you so so so very much for your feedback, I appreciate it so much.