-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad25913
commit a55cd9f
Showing
42 changed files
with
588 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
import {Receiver} from '#/receiver/receiver' | ||
import {Sender} from '#/sender/sender' | ||
import {Source} from '#/source/source' | ||
import {Target} from '#/target/target' | ||
import * as assert from '#assert' | ||
import std from '#std' | ||
import hae from '#utils/hae' | ||
|
||
export class Bridge { | ||
receiver: Receiver | ||
sender: Sender | ||
source: Source | ||
target: Target | ||
|
||
constructor(receiver: Receiver, sender: Sender) { | ||
this.receiver = receiver | ||
this.sender = sender | ||
constructor(source: Source, target: Target) { | ||
this.source = source | ||
this.target = target | ||
} | ||
|
||
async start() { | ||
std.log('starting receiver') | ||
await this.receiver.start() | ||
std.log('starting source') | ||
await this.source.start() | ||
|
||
std.log('starting sender') | ||
await this.sender.start() | ||
std.log('starting target') | ||
await this.target.start() | ||
|
||
await this.receiver.ready() | ||
std.log('receiver ready') | ||
await this.source.ready() | ||
std.log('source ready') | ||
|
||
await this.sender.ready() | ||
std.log('sender ready') | ||
await this.target.ready() | ||
std.log('target ready') | ||
|
||
std.log('bridge started') | ||
await this.receiver.receive( | ||
await this.source.receive( | ||
hae.log(async message => { | ||
std.log('bridging', {message}) | ||
|
||
assert.isNumber(message.id) | ||
assert.isArray(message.data) | ||
message.data.forEach(assert.isNumber) | ||
|
||
await this.sender.send(message) | ||
if (!this.receiver.continuous) await this.stop() | ||
await this.target.send(message) | ||
if (!this.source.continuous) await this.stop() | ||
}) | ||
) | ||
} | ||
|
||
async stop() { | ||
std.log('stopping bridge') | ||
await this.receiver.stop() | ||
await this.sender.stop() | ||
await this.source.stop() | ||
await this.target.stop() | ||
std.log('bridge stopped') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.