LocalSend TypeScript

LocalSend is an open source project for file sharing in local network.

TC;SC: https://github.com/CrossCopy/localsend-ts.git

Why?

Why I built this library.

My project crosscopy is abandoned for now. My focus has shifted to kunkun, which is a much larger superset of crosscopy. CrossCopy is just a few features in the design of Kunkun.

Kunkun already implemented a local network file transfer, and I am planning to implement P2P file transfer as well. However, one problem I have is cross-platform. Both CrossCopy and Kunkun are designed to be cross-platform, but at the moment I don’t have the capacity to build apps for mobile platforms. So it’s a good idea to start by integrating with existing cross-platform apps like LocalSend. So users can send files to Kunkun in local network when Kunkun’s mobile app isn’t ready yet.

Luckily, LocalSend already provides their protocol https://github.com/localsend/protocol So I just need to implement this protocol. I considered integrating it directly into the app with Rust, for the best performance. And there are existing Rust port of LocalSend

But I still want to start with a TypeScript implementation

  1. It’s easier to prototype with TypeScript
  2. There is no existing implementation in TypeScript
  3. I love TypeScript
  4. Implement LocalSend as a Kunkun extension to enrich extensions ecosystem; also as a demo/tutorial for writing more complicated extensions

I am going to make a extensions with this library. LocalSend already provides a CLI, so I am not sure if I should write another one. It should be simple. Writing a CLI could be helpful for me to test and experiment with this library.

Technical Stuff

  • LocalSend uses Multicast to discover other hosts
    • This is a more efficient way to broadcasting information than sending http request to each host (You don’t know who is online, so you need to send to everyone in the subnet)
  • I used Hono’s OpenAPI to generate openapi schema and type-safe client, then use the generated client to interact with the TS LocalSend hono server.
    • There is a cost though. With native http server and client, the bundle size is ~86KB, and increased to ~300KB+ with hono, valibot schema validation and openAPI schema docs.
    • But I don’t think it’s a big deal, 300KB is still pretty small. Once we can generate openAPI schema, clients in other languages can be easily generated.
Link to original