History

Rebind UDP socket when receiveHost/Port changed, jsdoc

Ada committed 10 months ago

Commit a4134b31 parent a29c9612 files · +113 −9Browse files

Showing the changes to interface/src/scripting/OSCScriptingInterface.h (1 of 2 files). Show all

Unified · Split

interface/src/scripting/OSCScriptingInterface.h+69−8
@@ -23,33 +23,94 @@ class ScriptValue; · 22 unmodified lines
2323 class ScriptEngine;
2424 class ScriptContext;
2525
26+/*@jsdoc
27+ * <p>Primarily for differentiating between OSC integers and floats,
28+ * since <code>Number</code> in JavaScript is always a 64-bit float.</p>
29+ * Supported OSC types are:
30+ * <ul>
31+ * <li><code>i</code> (32-bit integer)</li>
32+ * <li><code>f</code> (32-bit float)</li>
33+ * <li><code>s</code> (UTF-8 string)</li>
34+ * <li><code>b</code> (<code>ArrayBuffer</code>)</li>
35+ * <li><code>F</code> (boolean <code>false</code>)</li>
36+ * <li><code>T</code> (boolean <code>true</code>)</li>
37+ * <li><code>N</code> (<code>null</code>)</li>
38+ * </ul>
39+ * @typedef {Object} OSCSocket.TypedArgument
40+ * @property {string} type
41+ * @property {number|string|ArrayBuffer|boolean|null} value
42+ */
43+
44+/*@jsdoc
45+ * The <code>OSCSocket</code> API lets you send and receive Open Sound Control packets.
46+ * Despite the name, OSC is commonly used with VR applications too. It is used by some
47+ * tracking and haptic devices that aren't exposed through OpenVR or OpenXR.
48+ *
49+ * <p>Overte doesn't have any built-in OSC functionality; OSC is only useful with scripts.</p>
50+ *
51+ * @namespace OSCSocket
52+ *
53+ * @hifi-interface
54+ * @hifi-client-entity
55+ * @hifi-avatar
56+ *
57+ * @property {string} receiveHost - IP address for receiving OSC packets.
58+ * <code>127.0.0.1</code> by default, and shouldn't be changed unless
59+ * you know what you're doing and need to use something different.
60+ * @property {number} receivePort - IP port for receiving OSC packets.
61+ * <code>9000</code> by default.
62+ * @property {string} sendHost - IP address to send OSC packets to.
63+ * <code>127.0.0.1</code> by default, and shouldn't be changed unless
64+ * you know what you're doing and need to use something different.
65+ * @property {number} receivePort - IP port to send OSC packets to.
66+ * <code>9001</code> by default.
67+ */
2668 class OSCScriptingInterface : public QObject, public Dependency {
2769 Q_OBJECT
70+
71+ Q_PROPERTY(QString receiveHost READ getReceiveHost WRITE setReceiveHost)
72+ Q_PROPERTY(int receivePort READ getReceivePort WRITE setReceivePort)
73+
74+ Q_PROPERTY(QString sendHost READ getSendHost WRITE setSendHost)
75+ Q_PROPERTY(int sendPort READ getSendPort WRITE setSendPort)
76+
2877 public:
2978 OSCScriptingInterface(QObject* parent = nullptr);
3079 ~OSCScriptingInterface();
3180
3281 /*@jsdoc
33− * Sends an encoded OSC message. The target host address and port are accessible as the <code>osc/sendHost</code> and <code>osc/sendPort</code> settings. Changes to these settings do not apply until a restart.
34− * @function OSCSocket.sendMessage
35− * @param {string} address - The OSC address, starting with <code>/</code>
36− * @param {...*} [arguments] - OSC arguments. May be plain values, or in an object like <code>{ type: "i", value: 123 }</code>.
37− * Supported OSC types are <code>i</code> (32-bit int), <code>f</code> (32-bit float), <code>s</code> (UTF-8 string), <code>b</code> (<code>ArrayBuffer</code>), <code>F</code> (boolean false), <code>T</code> (boolean true), and <code>N</code> (<code>null</code>). OSC bundles are not supported.
82+ * Sends an encoded OSC packet. OSC bundles are not supported.
83+ * @function OSCSocket.sendPacket
84+ * @param {string} address - OSC address, starting with <code>/</code>
85+ * @param {...(OSCSocket.TypedArgument|number|string|ArrayBuffer|boolean|null)} [arguments]
3886 */
3987 static ScriptValue sendPacket(ScriptContext* context, ScriptEngine* engine);
4088
4189 signals:
4290 /*@jsdoc
43− * Triggered when an OSC packet is received. The receiving host address and port are accessible as the <code>osc/receiveHost</code> and <code>osc/receivePort</code> settings. Changes to these settings do not apply until a restart.
44− * @function OSCSocket.messageReceived
91+ * Triggered when an OSC packet is received. OSC bundles are not supported.
92+ * @function OSCSocket.packetReceived
4593 * @param {string} address - OSC address starting with <code>/</code>
46− * @param {Array.<Object.<string,*>>} arguments
94+ * @param {Array.<OSCSocket.TypedArgument>} arguments
4795 * @returns {Signal}
4896 */
4997 void packetReceived(const QString& address, const QVariantList& arguments);
5098
5199 private:
52100 void readPacket();
101+ void rebindSocket();
102+
103+ void setReceiveHost(QString host);
104+ QString getReceiveHost() const { return _receiveHost.get(); }
105+
106+ void setReceivePort(int port);
107+ int getReceivePort() const { return _receivePort.get(); }
108+
109+ void setSendHost(QString host);
110+ QString getSendHost() const { return _sendHost.get(); }
111+
112+ void setSendPort(int port);
113+ int getSendPort() const { return _sendPort.get(); }
53114
54115 Setting::Handle<int> _receivePort;
55116 Setting::Handle<QString> _receiveHost;