The handle to receive or send Open Sound Control (OSC) messages. This handle can be obtained by PlayerScript.oscHandle.

For more information about OSC, please also refer to the OSC section in the documentation.

Hierarchy

  • OscHandle

Methods

  • Gets whether the user has enabled OSC input.

    You can set it from "Enable OSC Receiver" in the "Other" tab of "Settings".

    Returns boolean

  • Gets whether the user has enabled OSC output.

    You can set it from "Enable OSC Sender" in the "Other" tab of "Settings".

    Returns boolean

  • Registers a callback to be called when an OSC message is received. The callback is called with an array of OscMessage received between the previous frame and the current frame. If called multiple times, only the last registration is valid.

    However, the callback is not called if any of the following conditions are met:

    • When isReceiveEnabled is false
    • When the network settings such as a firewall prevent receiving OSC messages
    • When the address of the received OSC message starts with /cluster/ (reserved by the system)

    Example

    // Log the received OSC messages
    _.oscHandle.onReceive(messages => {
    const lines = [];

    messages.forEach((message, i) => {
    const { address, timestamp, values } = message;

    lines.push(`== message [${i + 1}/${messages.length}]`);
    lines.push(`address: ${address}`);
    lines.push(`timestamp: ${new Date(timestamp).toLocaleString()}`);

    values.forEach((value, j) => {
    lines.push(`= value [${j + 1}/${values.length}]`);

    lines.push(`getInt(): ${value.getInt()}`);
    lines.push(`getFloat(): ${value.getFloat()}`);
    lines.push(`getAsciiString(): ${value.getAsciiString()}`);
    lines.push(`getBlobAsUint8Array(): ${value.getBlobAsUint8Array()}`);
    lines.push(`getBlobAsUtf8String(): ${value.getBlobAsUtf8String()}`);
    lines.push(`getBool(): ${value.getBool()}`);
    });
    });

    _.log(lines.join("\n"));
    });

    Parameters

    • callback: ((messages: OscMessage[]) => void)

      messages: The array of received OSC messages.

    Returns void

  • Attempts to send an OSC bundle or an OSC message.

    If any of the following conditions are met, a ClusterScriptError will occur and the bundle or message will fail to be sent.

    • isSendEnabled is false
    • The address of the OSC message to be sent does not start with /
    • The address of the OSC message to be sent starts with /cluster/ (reserved by the system)
    • The OSC message to be sent contains an invalid message or OscValue

    Due to the nature of the OSC system, there is no guarantee that the data you send will reach the destination server.

    Example

    // Send various OSC bundles and OSC messages
    _.oscHandle.send(new OscBundle([new OscMessage("/int", [OscValue.int(1)])]));
    _.oscHandle.send(new OscMessage("/float", [OscValue.float(2.3)]));
    _.oscHandle.send(new OscMessage("/string", [OscValue.asciiString("456")]));
    _.oscHandle.send(new OscMessage("/blob", [OscValue.blob("789")]));
    _.oscHandle.send(new OscMessage("/bool", [OscValue.bool(false)]));

    Parameters

    Returns void

Generated using TypeDoc