update docs & readme

This commit is contained in:
Rik Berkelder 2021-01-29 22:45:01 +01:00
parent 10074e197f
commit 8ae1307a17
3 changed files with 17 additions and 13 deletions

View file

@ -5,17 +5,15 @@ API Docs [here](https://riksolo.pages.riksolo.com/ts-osc/)
## Usage example ## Usage example
```javascript ```javascript
import {OSCClient, OSCType} from 'ts-osc'; import {OSCClient, OSCType, OSCServer} from 'ts-osc';
const client = new OSCClient({ const client = new OSCClient("localhost", 8000);
outHost: "localhost",
outPort: 8000,
inPort: 8000
})
client.send('/hello', OSCType.String, "hello"); client.send('/hello', OSCType.String, "hello");
client.on('message', (msg)=>{ const server = new OSCServer("0.0.0.0", 8000);
server.on('message', (msg)=>{
console.log(msg); console.log(msg);
}) })
``` ```

View file

@ -1,13 +1,12 @@
import * as dgram from 'dgram'; import * as dgram from 'dgram';
import { toBuffer } from 'osc-min'; import { toBuffer } from 'osc-min';
import { OSCArgument, OSCType, OSCArgumentType } from './types'; import { OSCArgument, OSCType, OSCArgumentType } from './types';
import { EventEmitter } from 'events';
/** /**
* OSC Client base class, handles sending and receiving OSC messages * OSC Client, handles sending OSC messages
``` ```
const osc = new OSCClient("192.168.0.44", 8000) const osc = new OSCClient("192.168.0.44", 8000);
``` ```
*/ */
export class OSCClient { export class OSCClient {
@ -27,7 +26,7 @@ export class OSCClient {
/** /**
* Send an OSC message * Send an OSC message
``` ```
osc.send("/osc/url", OSCType.String, "hello") osc.send("/osc/url", OSCType.String, "hello");
``` ```
*/ */

View file

@ -24,14 +24,21 @@ export declare interface OSCServer {
on(event: 'listening', listener: () => void): this; on(event: 'listening', listener: () => void): this;
} }
/**
* OSC Client, handles sending OSC messages
```
const osc = new OSCServer("192.168.0.44", 8000);
```
*/
export class OSCServer extends EventEmitter { export class OSCServer extends EventEmitter {
private socket: dgram.Socket; private socket: dgram.Socket;
constructor(address: string, port: number) { constructor(bindAddress: string, port: number) {
super(); super();
this.socket = dgram.createSocket({ type: 'udp4', reuseAddr: true }); this.socket = dgram.createSocket({ type: 'udp4', reuseAddr: true });
this.socket.bind(port, address); this.socket.bind(port, bindAddress);
this.socket.on('listening', () => { this.socket.on('listening', () => {
this.emit('listening'); this.emit('listening');