perfectmak / libra-core

A javascript client for libra built with typescript
https://npmjs.com/package/libra-core
136 stars 31 forks source link

Make it run on browser by using gRPC-web-text #28

Open totiz opened 5 years ago

totiz commented 5 years ago

I see that there's a lot of use case if we make this libra-core works directly on browser, and developer can use the same syntax as libra-core provided right now, so I make https://github.com/kulapio/libra-core that forked from this project and make it works on gRPC-web that some codes derived from https://github.com/bandprotocol/libra-web/ as well.

We make some changes for example. 1) use grp-web, js-sha3 package. 2) generate grpc-web protob for JS/TS with this script.

# Generate JavaScript/TypeScript for gRPC-web
protoc \
  --grpc-web_out=import_style=commonjs+dts,mode=grpcwebtext:$GEN_OUT_DIR \
  -I=${PROTO_IMPORT_DIR} \
  ${FILE_PATHS} \

3) the libra client init with this.

const client = new LibraClient({
    transferProtocol: 'https',
    host: 'ac-libra-testnet.kulap.io',
    port: '443',
    dataProtocol: 'grpc-web-text'
  })

4) perhaps if we init client directly to ac.testnet.libra.org we can use this config (WIP).

const client = new LibraClient({
    transferProtocol: 'socket',
    host: 'ac.testnet.libra.org',
    port: '80',
    dataProtocol: 'grpc'
  })
// or just default
const client = new LibraClient({ network: LibraNetwork.Testnet });

What do you think for kind of this changes? that I can do a PR for this.

perfectmak commented 5 years ago

Thank you. I've been considering using grpc-web too, but I have not had enough bandwidth to update work on that. I would very much appreciate your contribution to this.

Please go ahead and make a PR for this. Also a heads up that I'm currently in the middle of some refactoring to the codebase, Ideally, it shouldn't touch the client module that you will be working on, but so you are aware of the changes when I open a PR/merge it in.

totiz commented 5 years ago

Great, I'll PR soon. Now I'm working on Client config to support both Browser and Node, and perhaps some e2n testing on browser as well (may be come later).

totiz commented 5 years ago

Sorry for the delay, I'm facing problem when integrate gRPC-web with gPRC and it can not import('grpc') on the browser so we need to separate the codes and load only necessary libs on browser, I'll pr when it done.

perfectmak commented 5 years ago

Hi @totiz are you still working on this, let me know if there is anyway I can help?

totiz commented 5 years ago

@perfectmak Hi, I've finished on https://github.com/kulapio/libra-core/tree/master/lib/client with separate files for Node.js and Browser.js to prevent import grpc on broser (that will cause error). If you have time please check this https://github.com/kulapio/libra-core/tree/master/lib/client and let me know if any suggestion that I should do before PR. I've very busy this week and hope can finish the PR soon.

zoeyTM commented 5 years ago

Any updates on this @perfectmak @totiz ? Could really use the separate client-side bundle, so if there's anything I can contribute to help either of you please let me know :)

totiz commented 5 years ago

@morgansliman I still have problem with Angular, It need to hook into node_modules to comment some codes to make it works, I believe there'll be some solution to fix this in https://github.com/kulapio/libra-core and testing to make sure everyone work perfectly, that PR to upstream here.