-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: better internal organization
- Loading branch information
Showing
14 changed files
with
333 additions
and
305 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { AdapterHooks, Hooks, ResolveHooks } from "./hooks.ts"; | ||
import type { Peer } from "./peer.ts"; | ||
|
||
export function adapterUtils(peers: Set<Peer>) { | ||
return { | ||
peers, | ||
publish(topic: string, message: any, options) { | ||
const firstPeer = peers.values().next().value as Peer; | ||
if (firstPeer) { | ||
firstPeer.send(message, options); | ||
firstPeer.publish(topic, message, options); | ||
} | ||
}, | ||
} satisfies AdapterInstance; | ||
} | ||
|
||
// --- types --- | ||
|
||
export interface AdapterInstance { | ||
readonly peers: Set<Peer>; | ||
readonly publish: Peer["publish"]; | ||
} | ||
|
||
export interface AdapterOptions { | ||
resolve?: ResolveHooks; | ||
hooks?: Hooks; | ||
adapterHooks?: AdapterHooks; | ||
} | ||
|
||
export type Adapter< | ||
AdapterT extends AdapterInstance = AdapterInstance, | ||
Options extends AdapterOptions = AdapterOptions, | ||
> = (options?: Options) => AdapterT; | ||
|
||
export function defineWebSocketAdapter< | ||
AdapterT extends AdapterInstance = AdapterInstance, | ||
Options extends AdapterOptions = AdapterOptions, | ||
>(factory: Adapter<AdapterT, Options>) { | ||
return factory; | ||
} |
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
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
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.