roerohan / react-vnc

A React Component to connect to a websockified VNC client using noVNC.
https://roerohan.github.io/react-vnc/
MIT License
88 stars 21 forks source link

Accept rawChannel or url for VncScreen component #42

Open sklymoshenko opened 1 year ago

sklymoshenko commented 1 year ago

Is there an existing issue for this?

Use case description

Basically we have our own required implementation of creating a ws connection. We are not relying on third-part libraries to do it for us. It covers for us security and auth etc. noVnc package has support for accepting either url or already created ws channel to work with.

export default class RFB extends EventTargetMixin {
    constructor(target, urlOrChannel, options)     

So i am offering to accept not only url as string but alrerady created data channel and pass it to a rfb constructor. Wath do you think ?

Thank you!

Proposed solution (optional)

No response

roerohan commented 1 year ago

Seems fair, if noVNC supports it, this library should as well. Right now, if type-safety isn't a concern, I think you can still pass a raw channell object to the url field in VncScreen and it'll still work (as is evident from the following line(s) of code).

https://github.com/roerohan/react-vnc/blob/63be97bcfc418c7bc053ca76f54bb38c29ba7c38/src/lib/VncScreen.tsx#L231

I could make a change wherein if the url is absent but a channel is present, I pass that to the RFB constructor. If both are present however, it would accept the url field. (P.S. I don't want to make it urlOrChannel since I want it to be typed distinctly). Does this solution sound good? What do you think?

roerohan commented 1 year ago

@sklymoshenko could you share your thoughts on this? I'll update the source accordingly.