Showing the changes to interface/src/scripting/OSCScriptingInterface.h (1 of 2 files). Show all
Unified · Split
| @@ -23,33 +23,94 @@ class ScriptValue; · 22 unmodified lines | ||
| 23 | 23 | class ScriptEngine; |
| 24 | 24 | class ScriptContext; |
| 25 | 25 | |
| 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 | + */ | |
| 26 | 68 | class OSCScriptingInterface : public QObject, public Dependency { |
| 27 | 69 | 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 | + | |
| 28 | 77 | public: |
| 29 | 78 | OSCScriptingInterface(QObject* parent = nullptr); |
| 30 | 79 | ~OSCScriptingInterface(); |
| 31 | 80 | |
| 32 | 81 | /*@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] | |
| 38 | 86 | */ |
| 39 | 87 | static ScriptValue sendPacket(ScriptContext* context, ScriptEngine* engine); |
| 40 | 88 | |
| 41 | 89 | signals: |
| 42 | 90 | /*@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 | |
| 45 | 93 | * @param {string} address - OSC address starting with <code>/</code> |
| 46 | − * @param {Array.<Object.<string,*>>} arguments | |
| 94 | + * @param {Array.<OSCSocket.TypedArgument>} arguments | |
| 47 | 95 | * @returns {Signal} |
| 48 | 96 | */ |
| 49 | 97 | void packetReceived(const QString& address, const QVariantList& arguments); |
| 50 | 98 | |
| 51 | 99 | private: |
| 52 | 100 | 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(); } | |
| 53 | 114 | |
| 54 | 115 | Setting::Handle<int> _receivePort; |
| 55 | 116 | Setting::Handle<QString> _receiveHost; |