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

The creation of Trixi 2.0 #2

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
- name: Publish if version has been updated
uses: pascalgn/[email protected]
with:
tag_name: "v%s"
tag_message: "v%s"
create_tag: "true"
tag_name: 'v%s'
tag_message: 'v%s'
create_tag: 'true'
commit_pattern: "^Release (\\S+)"
publish_args: "--non-interactive"
publish_args: '--non-interactive'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ typings/

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
Expand All @@ -103,5 +102,5 @@ dist
# TernJS port file
.tern-port

testing/
/lib/
/lib/
/test/
674 changes: 0 additions & 674 deletions LICENSE

This file was deleted.

675 changes: 675 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

109 changes: 62 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
</h1>
</span>

Trixi is a WebSocket wrapper that enables developers to create better and stricter acpplications. The way we do this is that we use scoped socket interactions which allows you to have a scope for unidirectional payloads, operator based payloads, and bidirectional payloads. All of this is done through the use of a standardized payload schema.
Trixi is a WebSocket wrapper that enables developers to create better and stricter acpplications. The way we do this is that we use scoped socket interactions which allows you to have a scope for unidirectional payloads, operator based payloads, and bidirectional payloads. All of this is done through the use of a standardized payload schema.

# Unidirectional Payloads
If you need to send a payload with out the possibility of a response, then you can send a unidirectional payload, otherwise knon as an assertion. Both the client and server can send an assertion to each other, once the assertion is sent, it cannot be replied to in any way.

If you need to send a payload with out the possibility of a response, then you can send a unidirectional payload, otherwise knon as an assertion. Both the client and server can send an assertion to each other, once the assertion is sent, it cannot be replied to in any way.

```ts
import trixi from 'trixi';
import { Server } from 'http';
Expand All @@ -27,34 +29,39 @@ const app = trixi();
* Server Example
*/
httpServer.listen(8080, () => {
const server = app.createServer({ httpServer });

server.onConnection(connection => {
console.log("A new socket connection has been established from", connection.remoteAddress);

// Send your assertion message on start
connection.assert("Welcome...");

// Create a listener for assertions from the client
connection.onAssert(assertion => {
console.log("New assertion from client:", assertion.data);
});
});
const server = app.createServer({ httpServer });

server.onConnection((connection) => {
console.log(
'A new socket connection has been established from',
connection.remoteAddress
);

// Send your assertion message on start
connection.assert('Welcome...');

// Create a listener for assertions from the client
connection.onAssert((assertion) => {
console.log('New assertion from client:', assertion.data);
});
});
});

/**
* Client Example
*/
const client = app.createClient({ url: "ws://localhost:8080" });
client.assert("I have arrived!!");
const client = app.createClient({ url: 'ws://localhost:8080' });
client.assert('I have arrived!!');

client.onAssert(assertion => {
console.log("New assertion from server:", assertion.data);
client.onAssert((assertion) => {
console.log('New assertion from server:', assertion.data);
});
```

# Bidirectional Payloads
Sometimes you want to be able to hear back from your client when you send a message, so with bidirectional payloads, you'll be able to send a payload, and recieve payload in response if you so choose. When you response, it will be sent directionally to the original payload which you can start a listener for a response on.

Sometimes you want to be able to hear back from your client when you send a message, so with bidirectional payloads, you'll be able to send a payload, and recieve payload in response if you so choose. When you response, it will be sent directionally to the original payload which you can start a listener for a response on.

```ts
import trixi from 'trixi';
import { Server } from 'http';
Expand All @@ -66,34 +73,39 @@ const app = trixi();
* Server Example
*/
httpServer.listen(8080, () => {
const server = app.createServer({ httpServer });

server.onConnection(connection => {
console.log("A new socket connection has been established from", connection.remoteAddress);

// Create your listener
connection.onPayload(msg => {
console.log("Recieved a payload from the client", msg.data);
msg.reply({ recieved: true });
})
});
const server = app.createServer({ httpServer });

server.onConnection((connection) => {
console.log(
'A new socket connection has been established from',
connection.remoteAddress
);

// Create your listener
connection.onPayload((msg) => {
console.log('Recieved a payload from the client', msg.data);
msg.reply({ recieved: true });
});
});
});

/**
* Client Example
*/
const client = app.createClient({ url: "ws://localhost:8080" });
const client = app.createClient({ url: 'ws://localhost:8080' });

// Send a message to the server and await a response
client.send({ hello: "world" }).then(payload => {
payload.onResponse(response => {
console.log("Recieved response from the server", response.data);
})
client.send({ hello: 'world' }).then((payload) => {
payload.onResponse((response) => {
console.log('Recieved response from the server', response.data);
});
});
```

# Operator Payloads
Operator payloads are something that you can use to send a payload with a specific operator code attached to it. Once you send the operator payload, the client can listen for it and if it choose to, it can reply in the same manor as the bidrectional payload.

Operator payloads are something that you can use to send a payload with a specific operator code attached to it. Once you send the operator payload, the client can listen for it and if it choose to, it can reply in the same manor as the bidrectional payload.

```ts
import trixi from 'trixi';
import { Server } from 'http';
Expand All @@ -105,25 +117,28 @@ const app = trixi();
* Server Example
*/
httpServer.listen(8080, () => {
const server = app.createServer({ httpServer });
const server = app.createServer({ httpServer });

server.onConnection(connection => {
console.log("A new socket connection has been established from", connection.remoteAddress);
server.onConnection((connection) => {
console.log(
'A new socket connection has been established from',
connection.remoteAddress
);

// When a new connection is established, send the "hello:world" operator.
connection.sendOp("hello:world", { greeting: "Hello World" });
});
// When a new connection is established, send the "hello:world" operator.
connection.sendOp('hello:world', { greeting: 'Hello World' });
});
});

/**
* Client Example
*/
const client = app.createClient({ url: "ws://localhost:8080" });
const client = app.createClient({ url: 'ws://localhost:8080' });

// Create a listener on the operator "hello:world"
client.onOp("hello:world", e => {
console.log("New message on 'hello:world':", e.data);
client.onOp('hello:world', (e) => {
console.log("New message on 'hello:world':", e.data);
});
```

> **NOTE**: You can send a string or a json object as a payload.
> **NOTE**: You can send a string or a json object as a payload.
Loading