Compare commits

...

4 Commits

Author SHA1 Message Date
semantic-release-bot fcf45d0c03 chore(release): 0.1.0-develop.1 [skip ci]
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/libs5-transport-hyper/compare/v0.0.1...v0.1.0-develop.1) (2023-08-31)

### Features

* initial version ([53ddfc0](53ddfc03c9))
2023-08-31 22:27:22 +00:00
Derrick Hammer 77bd77ad47
ci: override moduleResolution 2023-08-31 18:25:05 -04:00
Derrick Hammer 9fef8dba10
ci: setup 2023-08-31 18:20:02 -04:00
Derrick Hammer 53ddfc03c9
feat: initial version 2023-08-31 18:13:57 -04:00
7 changed files with 19715 additions and 1 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

12
.presetterrc.json Normal file
View File

@ -0,0 +1,12 @@
{
"preset": [
"@lumeweb/node-library-preset"
],
"config": {
"tsconfig": {
"compilerOptions": {
"moduleResolution": "node"
}
}
}
}

6
CHANGELOG.md Normal file
View File

@ -0,0 +1,6 @@
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/libs5-transport-hyper/compare/v0.0.1...v0.1.0-develop.1) (2023-08-31)
### Features
* initial version ([53ddfc0](https://git.lumeweb.com/LumeWeb/libs5-transport-hyper/commit/53ddfc03c918aedbb57734bed84f7fcc93ef2520))

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2023 LumeWeb
Copyright (c) 2023 Hammer Technologies LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

19576
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

30
package.json Normal file
View File

@ -0,0 +1,30 @@
{
"name": "@lumeweb/libs5-transport-hyper",
"version": "0.1.0-develop.1",
"type": "module",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/libs5-transport-hyper.git"
},
"devDependencies": {
"@lumeweb/node-library-preset": "^0.2.7",
"presetter": "*"
},
"readme": "ERROR: No README data found!",
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"publishConfig": {
"access": "public"
},
"files": [
"lib"
],
"dependencies": {
"@lumeweb/libs5": "^0.1.0-develop.11",
"streamx": "^2.15.1"
}
}

77
src/index.ts Normal file
View File

@ -0,0 +1,77 @@
import { BasePeer, Logger } from "@lumeweb/libs5";
import { URL } from "url";
import { Buffer } from "buffer";
import { Readable } from "streamx";
export default class HyperTransportPeer extends BasePeer {
private _peer: any;
private _muxer: any;
private _protocol: string;
protected _socket = new Readable();
private _pipe?: any;
constructor(options: any) {
super(options);
const { peer, muxer, protocol } = options;
this._peer = peer;
this._muxer = muxer;
this._protocol = protocol;
}
public async init() {
const channel = await this._muxer.createChannel({
protocol: this._protocol,
});
const self = this;
this._pipe = await channel.addMessage({
async onmessage(m) {
if (m instanceof Uint8Array) {
m = Buffer.from(m);
}
self._socket.push(m);
},
});
await channel.open();
}
public static async connect(uri: URL): Promise<any> {
return Promise.reject("not supported");
}
listenForMessages(
callback: (event: any) => Promise<void>,
{
onDone,
onError,
logger,
}: {
onDone?: any;
onError?: (...args: any[]) => void;
logger: Logger;
},
): void {
this._socket.on("data", async (data: Buffer) => {
await callback(data);
});
if (onDone) {
this._socket.on("end", onDone);
}
if (onError) {
this._socket.on("error", onError);
}
}
renderLocationUri(): string {
return "Hypercore client";
}
sendMessage(message: Uint8Array): void {
this._pipe.write(message);
}
}