LiquidPlayer / LiquidCore

Node.js virtual machine for Android and iOS
MIT License
1.01k stars 127 forks source link

Expose service.getProcess().getContext() #142

Closed bangonkali closed 4 years ago

bangonkali commented 4 years ago

Hi @ericwlange, in relation to https://github.com/LiquidPlayer/LiquidCore/issues/138#issuecomment-558262820, it's totally up to you if it's safe to expose service.getProcess().getContext() and in what manner to expose the context. But it would really be handy if there was a standard way for this to be exposed especially that I could not get it from payload.getContext() https://github.com/LiquidPlayer/LiquidCore/issues/141.

ericwlange commented 4 years ago

BTW, here is the workaround to get the context in Android.

public static JSContext getJSContextFromMicroService(MicroService service) {
    final JSContext[] context_ = new JSContext[1];
    final Semaphore sync_ = new Semaphore(0);
    Process.EventListener listener = new Process.EventListener() {
        @Override public void onProcessStart(Process process, JSContext ctx) {
            context_[0] = ctx;
            sync_.release();
        }
        @Override public void onProcessAboutToExit(Process process, int exitCode) {}
        @Override public void onProcessExit(Process process, int exitCode) {}
        @Override public void onProcessFailed(Process process, Exception error) {}
    });
    service.getProcess().addEventListener(listener);
    sync_.acquireUninterruptibly();
    service.getProcess().removeEventListener(listener);
    return context_[0];
}
ericwlange commented 4 years ago

This feature has been added to 0.7.5

bangonkali commented 4 years ago

Thanks @ericwlange Looking forward to update on my end.