Skip to content

Commit

Permalink
chore(api): generate types, docs, fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
heapwolf committed Mar 31, 2024
1 parent b2abc6f commit f81e34c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 30 deletions.
2 changes: 2 additions & 0 deletions api/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ Key | Default Value | Description
:--- | :--- | :---
height | | The initial height of the first window in pixels or as a percentage of the screen.
width | | The initial width of the first window in pixels or as a percentage of the screen.
backgroundColorDark | "" | The initial color of the window in dark mode. If not provided, matches the current theme.
backgroundColorLight | "" | The initial color of the window in light mode. If not provided, matches the current theme.
titleBarStyle | "" | Determine if the titlebar style (hidden, hiddenInset)
max_height | 100% | Maximum height of the window in pixels or as a percentage of the screen.
max_width | 100% | Maximum width of the window in pixels or as a percentage of the screen.
Expand Down
36 changes: 19 additions & 17 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Returns the current window index
| :--- | :--- | :--- |
| Not specified | number | |

## [`createWindow(opts)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L196)
## [`createWindow(opts)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L198)

Creates a new window and returns an instance of ApplicationWindow.

Expand All @@ -47,6 +47,8 @@ Creates a new window and returns an instance of ApplicationWindow.
| opts.title | string | | true | the title of the window. |
| opts.titleBarStyle | string | | true | determines the style of the titlebar (MacOS only). |
| opts.trafficLightPosition | string | | true | a string (split on 'x') provides the x and y position of the traffic lights (MacOS only). |
| opts.backgroundColorDark | string | | true | determines the background color of the window in dark mode. |
| opts.backgroundColorLight | string | | true | determines the background color of the window in light mode. |
| opts.width | number \| string | | true | the width of the window. If undefined, the window will have the main window width. |
| opts.height | number \| string | | true | the height of the window. If undefined, the window will have the main window height. |
| opts.minWidth | number \| string | 0 | true | the minimum width of the window |
Expand All @@ -64,23 +66,23 @@ Creates a new window and returns an instance of ApplicationWindow.
| :--- | :--- | :--- |
| Not specified | Promise<ApplicationWindow> | |

### [`radius()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L221)
### [`radius()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L225)



### [`margin()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L226)
### [`margin()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L230)



## [`getScreenSize()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L294)
## [`getScreenSize()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L298)

Returns the current screen size.

| Return Value | Type | Description |
| :--- | :--- | :--- |
| Not specified | Promise<{ width: number, height: number | >} |

## [`getWindows(indices)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L320)
## [`getWindows(indices)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L324)

Returns the ApplicationWindow instances for the given indices or all windows if no indices are provided.

Expand All @@ -92,7 +94,7 @@ Returns the ApplicationWindow instances for the given indices or all windows if
| :--- | :--- | :--- |
| Not specified | Promise<ApplicationWindowList> | |

## [`getWindow(index)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L377)
## [`getWindow(index)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L381)

Returns the ApplicationWindow instance for the given index

Expand All @@ -104,15 +106,15 @@ Returns the ApplicationWindow instance for the given index
| :--- | :--- | :--- |
| Not specified | Promise<ApplicationWindow> | the ApplicationWindow instance or null if the window does not exist |

## [`getCurrentWindow()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L387)
## [`getCurrentWindow()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L391)

Returns the ApplicationWindow instance for the current window.

| Return Value | Type | Description |
| :--- | :--- | :--- |
| Not specified | Promise<ApplicationWindow> | |

## [`exit(code)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L396)
## [`exit(code)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L400)

Quits the backend process and then quits the render process, the exit code used is the final exit code to the OS.

Expand All @@ -124,7 +126,7 @@ Quits the backend process and then quits the render process, the exit code used
| :--- | :--- | :--- |
| Not specified | Promise<ipc.Result> | |

## [`setSystemMenu(options)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L493)
## [`setSystemMenu(options)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L497)

Set the native menu for the app.

Expand Down Expand Up @@ -219,11 +221,11 @@ Set the native menu for the app.
| :--- | :--- | :--- |
| Not specified | Promise<ipc.Result> | |
## [`setTrayMenu()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L500)
## [`setTrayMenu()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L504)
An alias to setSystemMenu for creating a tary menu
## [`setSystemMenuItemEnabled(value)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L509)
## [`setSystemMenuItemEnabled(value)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L513)
Set the enabled state of the system menu.
Expand All @@ -235,23 +237,23 @@ Set the enabled state of the system menu.
| :--- | :--- | :--- |
| Not specified | Promise<ipc.Result> | |
## [runtimeVersion](https://github.com/socketsupply/socket/blob/master/api/application.js#L517)
## [runtimeVersion](https://github.com/socketsupply/socket/blob/master/api/application.js#L521)
Socket Runtime version.
## [debug](https://github.com/socketsupply/socket/blob/master/api/application.js#L523)
## [debug](https://github.com/socketsupply/socket/blob/master/api/application.js#L527)
Runtime debug flag.
## [config](https://github.com/socketsupply/socket/blob/master/api/application.js#L529)
## [config](https://github.com/socketsupply/socket/blob/master/api/application.js#L533)
Application configuration.
## [backend](https://github.com/socketsupply/socket/blob/master/api/application.js#L534)
## [backend](https://github.com/socketsupply/socket/blob/master/api/application.js#L538)
The application's backend instance.
### [`open(opts)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L540)
### [`open(opts)`](https://github.com/socketsupply/socket/blob/master/api/application.js#L544)
Expand All @@ -264,7 +266,7 @@ The application's backend instance.
| :--- | :--- | :--- |
| Not specified | Promise<ipc.Result> | |
### [`close()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L548)
### [`close()`](https://github.com/socketsupply/socket/blob/master/api/application.js#L552)
Expand Down
2 changes: 2 additions & 0 deletions api/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ export function getCurrentWindowIndex () {
* @param {string=} opts.title - the title of the window.
* @param {string=} opts.titleBarStyle - determines the style of the titlebar (MacOS only).
* @param {string=} opts.trafficLightPosition - a string (split on 'x') provides the x and y position of the traffic lights (MacOS only).
* @param {string=} opts.backgroundColorDark - determines the background color of the window in dark mode.
* @param {string=} opts.backgroundColorLight - determines the background color of the window in light mode.
* @param {(number|string)=} opts.width - the width of the window. If undefined, the window will have the main window width.
* @param {(number|string)=} opts.height - the height of the window. If undefined, the window will have the main window height.
* @param {(number|string)=} [opts.minWidth = 0] - the minimum width of the window
Expand Down
23 changes: 18 additions & 5 deletions api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6056,6 +6056,8 @@ declare module "socket:application" {
* @param {string=} opts.title - the title of the window.
* @param {string=} opts.titleBarStyle - determines the style of the titlebar (MacOS only).
* @param {string=} opts.trafficLightPosition - a string (split on 'x') provides the x and y position of the traffic lights (MacOS only).
* @param {string=} opts.backgroundColorDark - determines the background color of the window in dark mode.
* @param {string=} opts.backgroundColorLight - determines the background color of the window in light mode.
* @param {(number|string)=} opts.width - the width of the window. If undefined, the window will have the main window width.
* @param {(number|string)=} opts.height - the height of the window. If undefined, the window will have the main window height.
* @param {(number|string)=} [opts.minWidth = 0] - the minimum width of the window
Expand All @@ -6082,6 +6084,8 @@ declare module "socket:application" {
title?: string | undefined;
titleBarStyle?: string | undefined;
trafficLightPosition?: string | undefined;
backgroundColorDark?: string | undefined;
backgroundColorLight?: string | undefined;
width?: (number | string) | undefined;
height?: (number | string) | undefined;
minWidth?: (number | string) | undefined;
Expand Down Expand Up @@ -10694,11 +10698,20 @@ declare module "socket:stream-relay/index" {
*/
export class Peer {
/**
* `Peer` class constructor. Avoid calling this directly (use the create method).
* @private
* @param {object?} [persistedState]
*/
private constructor();
* `Peer` class constructor.
* @param {object=} opts - Options
* @param {Buffer} opts.peerId - A 32 byte buffer (ie, `Encryption.createId()`).
* @param {Buffer} opts.clusterId - A 32 byte buffer (ie, `Encryption.createClusterId()`).
* @param {number=} opts.port - A port number.
* @param {number=} opts.probeInternalPort - An internal port number (semi-private for testing).
* @param {number=} opts.probeExternalPort - An external port number (semi-private for testing).
* @param {number=} opts.natType - A nat type.
* @param {string=} opts.address - An ipv4 address.
* @param {number=} opts.keepalive - The interval of the main loop.
* @param {function=} opts.siblingResolver - A function that can be used to determine canonical data in case two packets have concurrent clock values.
* @param {object} dgram - A nodejs compatible implementation of the dgram module (sans multicast).
*/
constructor(persistedState: {}, dgram: object);
port: any;
address: any;
natType: number;
Expand Down
20 changes: 12 additions & 8 deletions api/stream-relay/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ async function api (options = {}, events, dgram) {
const unpack = async packet => {
let opened
let verified
const sub = bus.subclusters.get(packet.subclusterId.toString('base64'))
const scid = Buffer.from(packet.subclusterId).toString('base64')
const sub = bus.subclusters.get(scid)
if (!sub) return {}

try {
opened = await _peer.open(packet.message, packet.subclusterId.toString('base64'))
opened = await _peer.open(packet.message, scid)
} catch (err) {
sub._emit('warning', err)
return {}
Expand Down Expand Up @@ -247,9 +248,10 @@ async function api (options = {}, events, dgram) {

for (const packet of packets) {
const p = Packet.from(packet)
_peer.cache.insert(packet.packetId.toString('hex'), p)
const pid = Buffer.from(packet.packetId).toString('hex')
_peer.cache.insert(pid, p)

_peer.unpublished[packet.packetId.toString('hex')] = Date.now()
_peer.unpublished[pid] = Date.now()
if (globalThis.navigator && !globalThis.navigator.onLine) continue

_peer.mcast(packet)
Expand All @@ -274,7 +276,8 @@ async function api (options = {}, events, dgram) {
sub.join = () => _peer.join(sub.sharedKey, options)

bus._on('#ready', () => {
const subcluster = bus.subclusters.get(sub.subclusterId.toString('base64'))
const scid = Buffer.from(sub.subclusterId).toString('base64')
const subcluster = bus.subclusters.get(scid)
if (subcluster) _peer.join(subcluster.sharedKey, options)
})

Expand All @@ -283,7 +286,8 @@ async function api (options = {}, events, dgram) {
}

bus._on('#join', async (packet, peer) => {
const sub = bus.subclusters.get(packet.subclusterId.toString('base64'))
const scid = Buffer.from(packet.subclusterId).toString('base64')
const sub = bus.subclusters.get(scid)
if (!sub) return

let ee = sub.peers.get(peer.peerId)
Expand Down Expand Up @@ -327,11 +331,11 @@ async function api (options = {}, events, dgram) {
})

const handlePacket = async (packet, peer, port, address) => {
const scid = packet.subclusterId.toString('base64')
const scid = Buffer.from(packet.subclusterId).toString('base64')
const sub = bus.subclusters.get(scid)
if (!sub) return

const eventName = packet.usr1.toString('hex')
const eventName = Buffer.from(packet.usr1).toString('hex')
const { verified, opened } = await unpack(packet)
if (verified) packet.verified = true

Expand Down

0 comments on commit f81e34c

Please sign in to comment.