Skip to content

Commit

Permalink
chore: docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Feb 17, 2024
1 parent a0022e6 commit af961e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/module-api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,16 @@ export abstract class InstanceBase<TConfig> implements InstanceBaseShared<TConfi
)
}

createSharedUdpSocket(options: SharedUdpSocketOptions, callback?: SharedUdpSocketMessageCallback): SharedUdpSocket
/**
* Create a shared udp socket.
* This can be neccessary for modules where the device/software sends UDP messages to a hardcoded port number. In those
* cases if you don't use this then it won't be possible to use multiple instances of you module.
* The api here is a subset of the `Socket` from the builtin `node:dgram`, but with Companion hosting the sockets instead of the module.
* @param type Type of udp to use
* @param callback Message received callback
*/
createSharedUdpSocket(type: 'udp4' | 'udp6', callback?: SharedUdpSocketMessageCallback): SharedUdpSocket
createSharedUdpSocket(options: SharedUdpSocketOptions, callback?: SharedUdpSocketMessageCallback): SharedUdpSocket
createSharedUdpSocket(
typeOrOptions: 'udp4' | 'udp6' | SharedUdpSocketOptions,
callback?: SharedUdpSocketMessageCallback
Expand Down
40 changes: 33 additions & 7 deletions src/module-api/shared-udp-socket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { /* Socket as DgramSocket, */ RemoteInfo } from 'dgram'
import type { RemoteInfo } from 'dgram'
import type { ModuleToHostEventsV0, HostToModuleEventsV0, SharedUdpSocketMessage } from '../host-api/api.js'
import type { IpcWrapper } from '../host-api/ipc-wrapper.js'
import EventEmitter from 'eventemitter3'
Expand All @@ -18,20 +18,46 @@ export interface SharedUdpSocketEvents {
export interface SharedUdpSocket extends EventEmitter<SharedUdpSocketEvents> {
// address()

bind(port: number, _address?: string, callback?: () => void): void

/**
* Bind to the shared socket. Until you call this, the shared socket will be inactive
* @param port Port number to listen on
* @param address (Unused) Local address to listen on
* @param callback Added to the `listening` event. Called once the socket is listening
*/
bind(port: number, address?: string, callback?: () => void): void

/**
* Close your reference to the shared socket.
* @param callback Called once the socket has closed
*/
close(callback?: () => void): void

/**
* Send a message from the shared socket
* @param bufferOrList Data to send
* @param port Target port number
* @param address Target address
* @param callback Callback to execute once the data has been sent
*/
send(
buffer: Buffer | DataView | string,
offset: number,
length: number,
bufferOrList: Buffer | DataView | string | Array<number>,
port: number,
address: string,
callback?: () => void
): void
/**
* Send a message from the shared socket
* @param bufferOrList Data to send
* @param offset Offset in the buffer to start sending from
* @param length Length of the data to send. Limited to the length of the bufer
* @param port Target port number
* @param address Target address
* @param callback Callback to execute once the data has been sent
*/
send(
bufferOrList: Buffer | DataView | string | Array<number>,
buffer: Buffer | DataView | string,
offset: number,
length: number,
port: number,
address: string,
callback?: () => void
Expand Down

0 comments on commit af961e0

Please sign in to comment.