Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very good project, but I think the interoperability between C # and JavaScript is so troublesome. #120

Open
HongChenLuYuan opened this issue Feb 11, 2023 · 6 comments
Labels
All OS enhancement New feature or request help wanted Extra attention is needed

Comments

@HongChenLuYuan
Copy link

Very good project, but I think the interoperability between C # and JavaScript is so troublesome.

@ottodobretsberger ottodobretsberger added question Further information is requested All OS labels Feb 16, 2023
@ottodobretsberger
Copy link
Contributor

Would you mind elaborating on what specific scenarios you find troublesome?

@HongChenLuYuan
Copy link
Author

HongChenLuYuan commented Feb 19, 2023

Messages can only be conveyed using string. In JavaScript, we also need to use the Switch statement for processing, which is very troublesome (especially in the vue project, I don't know what to do). Or is there a more detailed example?

I suggest that we can refer to the wails project. url address: https://wails.io/docs/howdoesitwork

@MikeYeager MikeYeager added enhancement New feature or request help wanted Extra attention is needed and removed question Further information is requested labels Feb 23, 2023
@MikeYeager
Copy link
Collaborator

@HongChenLuYuan This would be a nice addition to Photino, but not crucial as it only makes the dev experience a little nicer. It doesn't enable any new features or functionality. We will add this to our roadmap. Thanks for the suggestion.

@LauraWebdev
Copy link
Contributor

For reference, I've written a small parser that interfaces via JSON payloads. If there is interest, I'll split it out as a seperate library later on.

MessageParser.cs
Implementation in C#
Implementation in JS
Example Command

I'm also using mitt in Vue to broadcast Photino responses globally. Components can then listen to the events individually.

@rtmann
Copy link

rtmann commented Jul 24, 2023

As an alternative idea, you might want to consider not using send message, and use gRPC instead: https://github.com/grpc/grpc-dotnet

And offload all data requests to modern web workers to leverage true multithreading in JavaScript. This has the added benefit of making your app compatible with being run in other browsers. And instead of directly running a PhotinoWindow in the main console app thread, you can setup IOC/Services/Configuration etc and wire up gRPC, and then kick off PhotinoWindow in another thread separate from the main program thread.

This would give you the ability of enabling users to run the program as a server an access it from other browsers on their network while also letting them run it as an application if they'd prefer.

I think Photino's main strong point is it's not shipping an entire Chromium Embeded Framework with it, it's just using the browser control natively on the pc's already. But I think one of the main benefits of using a browser control for a UI is being able to seamlessly support a web site UI and a Desktop UI at the same time with the same code base.

If you start integrating with priority things in Photino it destroys that benefit.

Grpc is plenty fast.

@rtmann
Copy link

rtmann commented Sep 27, 2023

Personally, I opted not use the js/c# interoperability at all.

Instead I use Signal R on .Net 7 and it's compatible with Azure SignalR. I then design a proper Asp.net Web Api on .net 7 and I add and setup SignalR in it and design hubs.

This gives me a lot of advantages.... I.e. I can have multiple windows that all send/receive messages to signalr on the same contexts with a connection id for each window. And it runs on websockets and I get an automatic client side hub api (generated) and I can call backend apis, hardware etc from the client side signal r connection.

To run the api, I have "standalone" mode and "self hosted mode". In standalone mode, all my Console App does is host Photino and serve assets, that's it. In embeded mode my Photino app spins up IoC and setups Self Hosting Web Api stuff and self hosts the api so the photino app is hosting the web api and signalr connections itself and rendering photino. I just run the webapi on a separate thread so photino can have the main thread for the browser control ui work.

If I get around to it, I think I might try to contribute to this project and add some signalr / websocket packages/options.

Another option though would be to write a translation layer that compiles to webasm, so you can pass that "switch stuff" to the web asm code and let it do all the mapping and call out to the proper js interopt end point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
All OS enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants