Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readymade 3.1.0 #59

Merged
merged 25 commits into from
Nov 17, 2024
Merged

Readymade 3.1.0 #59

merged 25 commits into from
Nov 17, 2024

Conversation

steveblue
Copy link
Collaborator

@steveblue steveblue commented Oct 20, 2024

3.1.0

Readymade 3.1.0 Large Glass breaks the glass, adding new features that allow UI controls to communicate over WebSocket, WebRTC Data Channel, and Touch OSC.

@readymade/ui

  • new: RdDial has similar interface to RdSlider but action is limited to a rotary dial
  • new: documentation available at https://readymade-ui.github.io/readymade/#/lib
  • feat: RdControl can now be set via attribute or via setControl method on all inputs in @readymade/ui
  • feat: provide CSS styles for RdButton via setControl. Any provided styles are bound to the internal HTMLButtonElement

@readymade/transmit

  • feat: Transmitter is a new class for handling WebRTC DataChannel, WebSocket and Touch OSC communication.

Transmitter is a Swiss-army knife for communicating over WebRTC DataChannel, WebSocket or Touch OSC.

Getting Started

npm install @readymade/transmit
yarn add @readymade/transmit

Import Transmitter and instantiate with a configuration Object.

import { Transmitter, TransmitterConfig } from '@readymade/transmit';

const config: TransmitterConfig = {
  sharedKey: 'lobby',
  rtc: {
    iceServers,
  },
  serverConfig: {
    http: {
      protocol: 'http',
      hostname: 'localhost',
      port: 4449,
    },
    ws: {
      osc: {
        protocol: 'ws',
        hostname: 'localhost',
        port: 4445,
      },
      signal: {
        protocol: 'ws',
        hostname: 'localhost',
        port: 4446,
      },
      announce: {
        protocol: 'ws',
        hostname: 'localhost',
        port: 4447,
      },
      message: {
        protocol: 'ws',
        hostname: 'localhost',
        port: 4448,
      },
    },
  },
  onMessage,
  onConnect,
}

const transmitter = new Transmitter(config);

Messages

When signal and announce servers are configured, the instance of Transmitter will automatically attempt a handshake with a remote peer. If a peer is found, a WebRTC DataChannel peer to peer connection will open. To send a message over the data channel use the send method.

transmitter.send({ message: 'ping' });

If you want to send messages over WebSocket, use sendSocketMessage.

transmitter.sendSocketMessage({ message: 'ping' });

To send a message over TouchOSC, use sendTouchOSCMessage, ensuring the data your are sending follows the OSC protocol. Below is an example of sending a OSC message with type definitions.

transmitter.sendTouchOSCMessage('/OSCQUERY/Left Controls/Flip H', [
  {
    type: 'i',
    value: 1,
  },
]);

To listen for messages, inject a callback into the configuration. In the above example, onMessage would appear like so:

const onMessage = (message) => {
  if (message.payload.event === 'ping') {
    this.transmitter.send({ event: 'pong' });
  }
};

To react to a peer to peer connection, bind an onConnect callback to the configuration.

BREAKING CHANGES

RdControl type definition in @readymade/ui has been updated to normalize types for all controls and make type definitions more specific per control. RdLegacyControl is now exported which is the old type definition. The interface of all controls have been normalized, some properties are deprecated, while other shared properties are now moved to attributes that are unique to each control.

Before

interface RdControl {
  type: string;
  name: string;
  orient?: string;
  min?: number | number[];
  max?: number | number[];
  isActive?: boolean;
  placeSelf?: string;
  transform?: string;
  numberType?: 'int' | 'float';
}

After

interface RdControl<A> {
  type?: string;
  name: string;
  isActive?: boolean;
  hasUserInput?: boolean;
  hasRemoteInput?: boolean;
  currentValue?: number | string | Array<number> | Array<string> | boolean;
  timeStamp?: Date | number;
  attributes?: A;
}

For instance, in RdSlider which is a custom element that has several unique attributes, the type definition is now:

interface RdSliderAttributes {
  size?: string;
  height?: number;
  width?: number;
  orient?: string;
  min?: number | number[];
  max?: number | number[];
  position?: string;
  x?: number;
  y?: number;
  snapToCenter?: boolean;
  transform?: string;
  numberType?: 'int' | 'float';
}

RdControl<RdSliderAttributes>;

The reason for this change is to support @readymade/transmit. Passing an event from custom element to BroadcastChannel or any of the available channels in Transmitter is much simpler when the API is normalized.

fix: dial position on init

feat: better type definitions for controls
fix: setting 0 for currentValue on slider and dial

feat: make border-radius and border-width variables

fix: radio buttons had same name in lib.ts
feat: tweak dial styles

fix: remove deprecated view
…WebRTC DataChannel, WebSocket, and TouchOSC.
fix: transmit README
feat: version bump packages
@steveblue steveblue changed the title Controls Readymade 3.1.0 Nov 17, 2024
@steveblue steveblue merged commit fe9dcdf into readymade-ui:main Nov 17, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant