Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new Channel API #20731

Merged
merged 22 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
83e2a47
.eslintrc.json: setup some TypeScript rules
allisonkarlitskaya Jul 16, 2024
dc4c524
pkg/lib: move event/fsinfo/_internal into cockpit/
allisonkarlitskaya Jul 9, 2024
6c3bc0d
pkg/lib: transport: simplify binary frame pasting
allisonkarlitskaya Jul 2, 2024
733af26
pkg/lib: un-"export" Transport API
allisonkarlitskaya Jul 2, 2024
b199774
pkg/lib: transport: Convert function to a class
allisonkarlitskaya Jul 2, 2024
33a209c
pkg/lib: use EventEmitter on Transport API
allisonkarlitskaya Jul 9, 2024
dc1f037
pkg/lib: use arrows in Transport.constructor()
allisonkarlitskaya Jul 11, 2024
f7f84eb
pkg/lib: drop `self` in Transport.constructor
allisonkarlitskaya Jul 11, 2024
b786762
pkg/lib: convert Transport.constructor locals to privates
allisonkarlitskaya Jul 11, 2024
eeb9da3
pkg/lib: move methods out of Transport.constructor
allisonkarlitskaya Jul 11, 2024
8378b3a
pkg/lib: avoid `arguments` in transport.js
allisonkarlitskaya Jul 12, 2024
bd694cb
pkg/lib: simplify WebSocket setup code
allisonkarlitskaya Jul 12, 2024
4d8615e
pkg/lib: convert ParentWebSocket to class
allisonkarlitskaya Jul 12, 2024
acb708b
pkg/lib: port ParentWebSocket to TypeScript
allisonkarlitskaya Jul 12, 2024
9bc7d24
pkg/lib: remove public_transport hook
allisonkarlitskaya Jul 12, 2024
fb89172
pkg/lib: eliminate "out" filtering
allisonkarlitskaya Jul 12, 2024
de6c098
pkg/lib: eliminate parse_channel in transport.js
allisonkarlitskaya Jul 12, 2024
3134ad6
pkg/lib: simplify incoming filter logic
allisonkarlitskaya Jul 16, 2024
b0d7dc3
pkg/lib: step up type checking in Transport
allisonkarlitskaya Jul 16, 2024
5a8e2e8
pkg/lib: convert transport_globals to a class
allisonkarlitskaya Jul 16, 2024
b966834
pkg/lib: port Transport to TypeScript
allisonkarlitskaya Jul 16, 2024
2d0fda8
pkg/lib: add new public "Channel" API
allisonkarlitskaya Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,30 @@
"plugins": [
"@typescript-eslint"
],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"extends": "plugin:@typescript-eslint/recommended",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json"]
},
"rules": {
// https://typescript-eslint.io/rules/no-use-before-define
// Note: you must disable the base rule as it can report incorrect errors
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "error",

// as recommended by https://typescript-eslint.io/rules/no-unused-vars/
"@typescript-eslint/no-unused-vars": [
"error",
{
"args": "all",
"argsIgnorePattern": "^_",
"caughtErrors": "all",
"caughtErrorsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"ignoreRestSiblings": true
}
]
}
}
],
Expand Down
6 changes: 2 additions & 4 deletions doc/guide/cockpit-channel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,10 @@ cockpit.transport.close([problem])
<refsection id="cockpit-transport-filter">
<title>cockpit.transport.filter()</title>
<programlisting>
cockpit.transport.filter((message, channelid, control) => { ... }, [out])
cockpit.transport.filter((message, channelid, control) => { ... })
</programlisting>
<para>Add a filter to the underlying channel transport. All incoming messages will be
passed to each of the filter callbacks that are registered. If the <code>out</code>
argument is equal to <code>true</code> then the filter will receive outgoing messages
that being sent on the underlying channel transport.</para>
passed to each of the filter callbacks that are registered.</para>
<para>This function is rarely used.</para>
<para>Filter callbacks are called in the order they are registered. If a filter
callback returns <code>false</code> then the message will not be dispatched
Expand Down
1 change: 1 addition & 0 deletions files.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const info = {
"base1/test-browser-storage.js",
"base1/test-cache.js",
"base1/test-chan.js",
"base1/test-channel.ts",
"base1/test-dbus-address.js",
"base1/test-dbus-framed.js",
"base1/test-dbus.js",
Expand Down
36 changes: 0 additions & 36 deletions pkg/base1/test-chan.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,42 +719,6 @@ QUnit.test("filter message in", function (assert) {
channel.send("three");
});

QUnit.test("filter message out", function (assert) {
const done = assert.async();
assert.expect(10);

let filtered = 0;
let filtering = true;
cockpit.transport.filter(function(message, channelid, control) {
if (!filtering)
return true;
if (message[0] == '\n') {
assert.strictEqual(channelid, "", "control message channel");
assert.equal(typeof control, "object", "control is a JSON object");
assert.equal(typeof control.command, "string", "control has a command");
} else {
assert.strictEqual(channelid, channel.id, "cockpit channel id");
assert.equal(control, undefined, "control is undefined");
filtered += 1;

if (filtered != 1) {
channel.close();
filtering = false;
done();
return false;
}

return true;
}
return false;
}, true);

const channel = cockpit.channel({ payload: "null" });
channel.send("one");
channel.send("two");
channel.send("three");
});

QUnit.test("inject message out", function (assert) {
const done = assert.async();
assert.expect(4);
Expand Down
Loading