Code Monkey home page Code Monkey logo

Comments (24)

dstreet avatar dstreet commented on May 22, 2024 1

@mkozjak mongoose handles this situation pretty well without needing to publish the dist. I might be able to put together a PR sometime today.

from rpc-websockets.

dstreet avatar dstreet commented on May 22, 2024 1

@mkozjak I got slammed with some other project work. I'm not sure when I'll have time to get to this, sorry.

from rpc-websockets.

mkozjak avatar mkozjak commented on May 22, 2024 1

Awesome work, @dstreet! Thanks!
Will wait for @soulhunter1987 to check up on it just in case and publish the update afterwards.

from rpc-websockets.

mkozjak avatar mkozjak commented on May 22, 2024 1

@dstreet I will publish this release now. If it works for you, I am okay with it.

from rpc-websockets.

dstreet avatar dstreet commented on May 22, 2024 1

@mkozjak Looks like you forgot to rebuild the dist before publishing to npm. I apologize if this was a miscommunication on my part

from rpc-websockets.

mkozjak avatar mkozjak commented on May 22, 2024

Browser tests should also be included.

#zuul
#saucelabs

from rpc-websockets.

ekzobrain avatar ekzobrain commented on May 22, 2024

What about this issue? Generally current Client logic is fully appropriate for browser usage. The only main problem, as i see, is uws usage, which must be replaced with native WebSockets for browser.

from rpc-websockets.

mkozjak avatar mkozjak commented on May 22, 2024

Hi, @soulhunter1987!

For the browser we use browserify, which will take care of our client code.
After installing rpc-websockets, you can copy file ./dist/index.browser.js to your frontend code, since browserify bundled the entire library there for you.
An RPCWebSocket class is exposed there for you to use.

This is an example html: https://gist.github.com/mkozjak/fa9296484c40445af516e563c65536bf

Cheers!

from rpc-websockets.

ekzobrain avatar ekzobrain commented on May 22, 2024

That will do the job but, not very efficiently. It would be good to also allow compiling from source with webpack or some other bundling tools. That would allow to write ES6-style code and then bundle (and may be transpile for old browsers) it as appropriate for the project. Also it would reduce size of resulting bundle, because repeating dependencies would be included only once.

from rpc-websockets.

ekzobrain avatar ekzobrain commented on May 22, 2024

Automatic updates via npm/yarn are also not available with this approach, because one will need to copy new file to his project's public directory (of course that may be automated, but that's extra work).

from rpc-websockets.

ekzobrain avatar ekzobrain commented on May 22, 2024

index.browser.js is really HUGE now, because it includes uws (which is not needed there at all), eventemitter and many other libraries, which may already be used in the project.

from rpc-websockets.

mkozjak avatar mkozjak commented on May 22, 2024

Agreed. TBH, I'm not really experienced with bundlers, so could you point me in the right direction with some examples, maybe? Also, PR welcome!

from rpc-websockets.

ekzobrain avatar ekzobrain commented on May 22, 2024

First of all you need to supply "src" directory in the package along with "dist".
Then one approach is to manually import and pass "transport" object (uws or browser websocket) to Client constructor via dependency injection.
NodeJs usage would look like this then:

import WebSocket from 'uws';
import {Client} from 'rpc-websocket';

connection = new Client(address, options, WebSocket)
connection.call(...)

And browser ES6 code would be:

import {Client, WebSocketWrapper} from 'rpc-websocket';

connection = new Client(address, options, WebSocketWrapper)
connection.call(...)

where "WebSocketWrapper" is your src/lib/client/websocket.browser.js wrapper class.

So with this approach you give users a choice which transport to use. And it would allow usage of any other transport which implements compatible interface.

from rpc-websockets.

ekzobrain avatar ekzobrain commented on May 22, 2024

If you create a separate branch with this solution implemented - I could try and test it's browser usage.

from rpc-websockets.

mkozjak avatar mkozjak commented on May 22, 2024

@soulhunter1987: Can you please give me an example library/project where both src and dist are shipped and dependencies are handled like described?

from rpc-websockets.

mkozjak avatar mkozjak commented on May 22, 2024

@dstreet: I believe you meant 'src', since the dist directory should definitely be published. :)

from rpc-websockets.

dstreet avatar dstreet commented on May 22, 2024

Sorry, let me revise what I said. The src can be shipped so that clients can bundle and build from source using Browserify or Webpack. dist would still need to be shipped because of the dependency on Babel.

from rpc-websockets.

dstreet avatar dstreet commented on May 22, 2024

Finally got some time to work on this. I'll submit a PR soon.

from rpc-websockets.

dstreet avatar dstreet commented on May 22, 2024

Submitted PR #13. @soulhunter1987 can you test this on your end?

from rpc-websockets.

dstreet avatar dstreet commented on May 22, 2024

Great, thanks!

from rpc-websockets.

dstreet avatar dstreet commented on May 22, 2024

@soulhunter1987 Do you think you'll have time to review this soon? Turns out I need this for a project I'm working on.

from rpc-websockets.

mkozjak avatar mkozjak commented on May 22, 2024

@dstreet I forgot to include the dist directory altogether. It was still in .gitignore.

from rpc-websockets.

mkozjak avatar mkozjak commented on May 22, 2024

@dstreet Published. Can you check on it, please?

from rpc-websockets.

dstreet avatar dstreet commented on May 22, 2024

Still broken, but I found where the problem is. commit 2c20ddd reverted the change I had made to the build script

from rpc-websockets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.