Skip to content

Commit

Permalink
Typescript port (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellmcc authored Oct 14, 2024
1 parent 0ac01f2 commit 73cf403
Show file tree
Hide file tree
Showing 27 changed files with 10,536 additions and 2,278 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
run-name: CI

on:
push:
branches:
- "*"

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
- run: npm ci
- run: npm run lint
- run: npm test
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
examples/*.js
build/*.js
/coverage.html
/lib/osc-utilities.js
dist/


10 changes: 7 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
node_modules/
build/
coverage.html
node_modules
lib/
test/
examples/
eslint.config.mjs
tsconfig.json
.github/
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

39 changes: 0 additions & 39 deletions Cakefile

This file was deleted.

68 changes: 68 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import preferArrowFunctions from "eslint-plugin-prefer-arrow-functions";
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import globals from "globals";
export default [
{
ignores: ["**/dist", "**/test", "**/eslint.config.mjs"],
},
eslint.configs.recommended,
...tseslint.configs.strict,
...tseslint.configs.stylistic,
{
plugins: {
"prefer-arrow-functions": preferArrowFunctions,
},
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],

"@typescript-eslint/no-non-null-assertion": "off",

"@typescript-eslint/restrict-template-expressions": [
"error",
{
allowNumber: true,
},
],

"@typescript-eslint/no-unnecessary-condition": [
"error",
{
allowConstantLoopConditions: true,
},
],

"prefer-arrow-functions/prefer-arrow-functions": [
"error",
{
returnStyle: "implicit",
},
],

"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"no-warning-comments": "error",
},
},
{
files: ["**/examples/*.mjs", "**/examples/*.js"],
...tseslint.configs.disableTypeChecked,
},
{
files: ["**/examples/*.mjs", "**/examples/*.js"],
languageOptions: {
globals: globals.node,
},
},
];
38 changes: 0 additions & 38 deletions examples/osc-float-to-int.coffee

This file was deleted.

31 changes: 31 additions & 0 deletions examples/osc-float-to-int.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as osc from "osc-min";
import * as dgram from "dgram";

const inport = process.argv[2] != null ? parseInt(process.argv[2]) : 41234;
const outport = process.argv[3] != null ? parseInt(process.argv[3]) : 41235;

const float_to_int = (message) => {
for (const arg of message.args) {
if (arg.type === "float") {
arg.type = "integer";
}
}
return message;
};

const sock = dgram.createSocket("udp4", (msg) => {
try {
const edited = osc.applyMessageTransform(msg, (message) =>
float_to_int(message)
);
return sock.send(edited, 0, edited.byteLength, outport, "localhost");
} catch (error) {
return console.log("error redirecting", error);
}
});

sock.bind(inport);

console.log("OSC redirecter running at http://localhost:" + inport);

console.log("translating messages to http://localhost:" + outport);
35 changes: 0 additions & 35 deletions examples/osc-redirect.coffee

This file was deleted.

28 changes: 28 additions & 0 deletions examples/osc-redirect.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as osc from "osc-min";
import * as dgram from "dgram";

const inport = process.argv[2] != null ? parseInt(process.argv[2]) : 41234;
const outport = process.argv[3] != null ? parseInt(process.argv[3]) : 41235;

console.log(`OSC redirecter running at http://localhost:${inport}`);
console.log(`redirecting messages to http://localhost:${outport}`);

const sock = dgram.createSocket("udp4", (msg) => {
try {
const redirected = osc.applyAddressTransform(
msg,
(address) => `/redirect${address}`
);
return sock.send(
redirected,
0,
redirected.byteLength,
outport,
"localhost"
);
} catch (e) {
return console.log(`error redirecting: ${e}`);
}
});

sock.bind(inport);
44 changes: 0 additions & 44 deletions examples/oscbundle_heartbeat.coffee

This file was deleted.

35 changes: 35 additions & 0 deletions examples/oscbundle_heartbeat.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as osc from "osc-min";
import * as dgram from "dgram";

const udp = dgram.createSocket("udp4");

const outport = process.argv[2] != null ? parseInt(process.argv[2]) : 41234;

const sendHeartbeat = () => {
const buf = osc.toBuffer({
timetag: new Date(new Date().getTime() + 50),
elements: [
{
address: "/p1",
args: new TextEncoder().encode("beat"),
},
{
address: "/p2",
args: "string",
},
{
timetag: new Date(new Date().getTime() + 1000),
elements: [
{
address: "/p3",
args: 12,
},
],
},
],
});
return udp.send(buf, 0, buf.byteLength, outport, "localhost");
};

setInterval(sendHeartbeat, 2000);
console.log(`sending heartbeat messages to http://localhost:${outport}`);
Loading

0 comments on commit 73cf403

Please sign in to comment.