Merge pull request #12143 from ctrlaltdavid/21679

location API JSDoc
This commit is contained in:
MiladNazeri 2018-01-16 12:32:25 -08:00 committed by GitHub
commit d356f4faf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 292 additions and 2 deletions

View file

@ -31,6 +31,32 @@ const QString INDEX_PATH = "/";
const QString GET_PLACE = "/api/v1/places/%1";
/**jsdoc
* The location API provides facilities related to your current location in the metaverse.
*
* @namespace location
* @property {Uuid} domainId - A UUID uniquely identifying the domain you're visiting. Is {@link Uuid|Uuid.NULL} if you're not
* connected to the domain.
* <em>Read-only.</em>
* @property {string} hostname - The name of the domain for your current metaverse address (e.g., <code>"AvatarIsland"</code>,
* <code>localhost</code>, or an IP address).
* <em>Read-only.</em>
* @property {string} href - Your current metaverse address (e.g., <code>"hifi://avatarisland/15,-10,26/0,0,0,1"</code>)
* regardless of whether or not you're connected to the domain.
* <em>Read-only.</em>
* @property {boolean} isConnected - <code>true</code> if you're connected to the domain in your current <code>href</code>
* metaverse address, otherwise <code>false</code>.
* <em>Read-only.</em>
* @property {string} pathname - The location and orientation in your current <code>href</code> metaverse address
* (e.g., <code>"/15,-10,26/0,0,0,1"</code>).
* <em>Read-only.</em>
* @property {string} placename - The place name in your current <code>href</code> metaverse address
* (e.g., <code>"AvatarIsland"</code>). Is blank if your <code>hostname</code> is an IP address.
* <em>Read-only.</em>
* @property {string} protocol - The protocol of your current <code>href</code> metaverse address (e.g., <code>"hifi"</code>).
* <em>Read-only.</em>
*/
class AddressManager : public QObject, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
@ -42,10 +68,77 @@ class AddressManager : public QObject, public Dependency {
Q_PROPERTY(QString placename READ getPlaceName)
Q_PROPERTY(QString domainId READ getDomainId)
public:
/**jsdoc
* Get Interface's protocol version.
* @function location.protocolVersion
* @returns {string} A string uniquely identifying the version of the metaverse protocol that Interface is using.
*/
Q_INVOKABLE QString protocolVersion();
using PositionGetter = std::function<glm::vec3()>;
using OrientationGetter = std::function<glm::quat()>;
/**jsdoc
* <p>The reasons for an address lookup via the metaverse API are defined by numeric values:</p>
* <table>
* <thead>
* <tr>
* <th>Name</th>
* <th>Value</th>
* <th>Description</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <td><strong>UserInput</strong></td>
* <td><code>0</code></td>
* <td>User-typed input.</td>
* </tr>
* <tr>
* <td><strong>Back</strong></td>
* <td><code>1</code></td>
* <td>Address from a {@link location.goBack|goBack} call.</td>
* </tr>
* <tr>
* <td><strong>Forward</strong></td>
* <td><code>2</code></td>
* <td>Address from a {@link location.goForward|goForward} call.</td>
* </tr>
* <tr>
* <td><strong>StartupFromSettings</strong></td>
* <td><code>3</code></td>
* <td>Initial location at Interface start-up from settings.</td>
* </tr>
* <tr>
* <td><strong>DomainPathResponse</strong></td>
* <td><code>4</code></td>
* <td>A named path in the domain.</td>
* </tr>
* <tr>
* <td><strong>Internal</strong></td>
* <td><code>5</code></td>
* <td>An internal attempt to resolve an alternative path.</td>
* </tr>
* <tr>
* <td><strong>AttemptedRefresh</strong></td>
* <td><code>6</code></td>
* <td>A refresh after connecting to a domain.</td>
* </tr>
* <tr>
* <td><strong>Suggestions</strong></td>
* <td><code>7</code></td>
* <td>Address from the Goto dialog.</td>
* </tr>
* <tr>
* <td><strong>VisitUserFromPAL</strong></td>
* <td><code>8</code></td>
* <td>User from the People dialog.</td>
* </tr>
* </tbody>
* </table>
* @typedef location.LookupTrigger
*/
enum LookupTrigger {
UserInput,
Back,
@ -83,43 +176,240 @@ public:
const QStack<QUrl>& getForwardStack() const { return _forwardStack; }
public slots:
/**jsdoc
* Go to a specified metaverse address.
* @function location.handleLookupString
* @param {string} address - The address to go to: a <code>"hifi:/"<code> address, an IP address (e.g.,
* <code>"127.0.0.1"</code> or <code>"localhost"</code>), a domain name, a named path on a domain (starts with
* <code>"/"</code>), a position or position and orientation, or a user (starts with <code>"@"</code>).
* @param {boolean} fromSuggestions=false - Set to <code>true</code> if the address is obtained from the "Goto" dialog.
* Helps ensure that user's location history is correctly maintained.
*/
void handleLookupString(const QString& lookupString, bool fromSuggestions = false);
/**jsdoc
* Go to a position and orientation resulting from a lookup for a named path in the domain (set in the domain server's
* settings).
* @function location.goToViewpointForPath
* @param {string} path - The position and orientation corresponding to the named path.
* @param {string} namedPath - The named path that was looked up on the server.
* @deprecated This function is deprecated and will be removed.
*/
// This function is marked as deprecated in anticipation that it will not be included in the JavaScript API if and when the
// functions and signals that should be exposed are moved to a scripting interface class.
//
// we currently expect this to be called from NodeList once handleLookupString has been called with a path
bool goToViewpointForPath(const QString& viewpointString, const QString& pathString)
{ return handleViewpoint(viewpointString, false, DomainPathResponse, false, pathString); }
/**jsdoc
* Go back to the previous location in your navigation history, if there is one.
* @function location.goBack
*/
void goBack();
/**jsdoc
* Go forward to the next location in your navigation history, if there is one.
* @function location.goForward
*/
void goForward();
/**jsdoc
* Go to the local Sandbox server that's running on the same PC as Interface.
* @function location.goToLocalSandbox
* @param {string} path="" - The position and orientation to go to (e.g., <code>"/0,0,0"</code>).
* @param {location.LookupTrigger} trigger=StartupFromSettings - The reason for the function call. Helps ensure that user's
* location history is correctly maintained.
*/
void goToLocalSandbox(QString path = "", LookupTrigger trigger = LookupTrigger::StartupFromSettings) { handleUrl(SANDBOX_HIFI_ADDRESS + path, trigger); }
/**jsdoc
* Go to the default "welcome" metaverse address.
* @function location.goToEntry
* @param {location.LookupTrigger} trigger=StartupFromSettings - The reason for the function call. Helps ensure that user's
* location history is correctly maintained.
*/
void goToEntry(LookupTrigger trigger = LookupTrigger::StartupFromSettings) { handleUrl(DEFAULT_HIFI_ADDRESS, trigger); }
/**jsdoc
* Go to the specified user's location.
* @function location.goToUser
* @param {string} username - The user's username.
* @param {boolean} matchOrientation=true - If <code>true</code> then go to a location just in front of the user and turn to face
* them, otherwise go to the user's exact location and orientation.
*/
void goToUser(const QString& username, bool shouldMatchOrientation = true);
/**jsdoc
* Refresh the current address, e.g., after connecting to a domain in order to position the user to the desired location.
* @function location.refreshPreviousLookup
* @deprecated This function is deprecated and will be removed.
*/
// This function is marked as deprecated in anticipation that it will not be included in the JavaScript API if and when the
// functions and signals that should be exposed are moved to a scripting interface class.
void refreshPreviousLookup();
/**jsdoc
* Update your current metaverse location in Interface's {@link Settings} file as your last-known address. This can be used
* to ensure that you start up at that address if you exit Interface without a later address automatically being saved.
* @function location.storeCurrentAddress
*/
void storeCurrentAddress();
/**jsdoc
* Copy your current metaverse address (i.e., <code>location.href</code> property value) to the OS clipboard.
* @function location.copyAddress
*/
void copyAddress();
/**jsdoc
* Copy your current metaverse location and orientation (i.e., <code>location.pathname</code> property value) to the OS
* clipboard.
* @function location.copyPath
*/
void copyPath();
/**jsdoc
* Retrieve and remember the place name for the given domain ID if the place name is not already known.
* @function location.lookupShareableNameForDomainID
* @param {Uuid} domainID - The UUID of the domain.
* @deprecated This function is deprecated and will be removed.
*/
// This function is marked as deprecated in anticipation that it will not be included in the JavaScript API if and when the
// functions and signals that should be exposed are moved to a scripting interface class.
void lookupShareableNameForDomainID(const QUuid& domainID);
signals:
/**jsdoc
* Triggered when looking up the details of a metaverse user or location to go to has completed (successfully or
* unsuccessfully).
* @function location.lookupResultsFinished
* @returns {Signal}
*/
void lookupResultsFinished();
/**jsdoc
* Triggered when looking up the details of a metaverse user or location to go to has completed and the domain or user is
* offline.
* @function location.lookupResultIsOffline
* @returns {Signal}
*/
void lookupResultIsOffline();
/**jsdoc
* Triggered when looking up the details of a metaverse user or location to go to has completed and the domain or user could
* not be found.
* @function location.lookupResultIsNotFound
* @returns {Signal}
*/
void lookupResultIsNotFound();
/**jsdoc
* Triggered when a request is made to go to an IP address.
* @function location.possibleDomainChangeRequired
* @param {string} hostName - The name of the domain to go do.
* @param {number} port - The integer number of the network port to connect to.
* @param {Uuid} domainID - The UUID of the domain to go to.
* @returns {Signal}
*/
// No example because this function isn't typically used in scripts.
void possibleDomainChangeRequired(const QString& newHostname, quint16 newPort, const QUuid& domainID);
/**jsdoc
* Triggered when a request is made to go to a named domain or user.
* @function location.possibleDomainChangeRequiredViaICEForID
* @param {string} iceServerHostName - IP address of the ICE server.
* @param {Uuid} domainID - The UUID of the domain to go to.
* @returns {Signal}
*/
// No example because this function isn't typically used in scripts.
void possibleDomainChangeRequiredViaICEForID(const QString& iceServerHostname, const QUuid& domainID);
/**jsdoc
* Triggered when an attempt is made to send your avatar to a specified position on the current domain. For example, when
* you change domains or enter a position to go to in the "Goto" dialog.
* @function location.locationChangeRequired
* @param {Vec3} position - The position to go to.
* @param {boolean} hasOrientationChange - If <code>true</code> then a new <code>orientation</code> has been requested.
* @param {Quat} orientation - The orientation to change to. Is {@link Quat(0)|Quat.IDENTITY} if
* <code>hasOrientationChange</code> is <code>false</code>.
* @param {boolean} shouldFaceLocation - If <code>true</code> then the request is to go to a position near that specified
* and orient your avatar to face it. For example when you visit someone from the "People" dialog.
* @returns {Signal}
* @example <caption>Report location change requests.</caption>
* function onLocationChangeRequired(newPosition, hasOrientationChange, newOrientation, shouldFaceLocation) {
* print("Location change required:");
* print("- New position = " + JSON.stringify(newPosition));
* print("- Has orientation change = " + hasOrientationChange);
* print("- New orientation = " + JSON.stringify(newOrientation));
* print("- Should face location = " + shouldFaceLocation);
* }
*
* location.locationChangeRequired.connect(onLocationChangeRequired);
*/
void locationChangeRequired(const glm::vec3& newPosition,
bool hasOrientationChange, const glm::quat& newOrientation,
bool shouldFaceLocation);
/**jsdoc
* Triggered when an attempt is made to send your avatar to a new named path on the domain (set in the domain server's
* settings). For example, when you enter a "/" followed by the path's name in the "GOTO" dialog.
* @function location.pathChangeRequired
* @param {string} path - The name of the path to go to.
* @returns {Signal}
* @example <caption>Report path change requests.</caption>
* function onPathChangeRequired(newPath) {
* print("onPathChangeRequired: newPath = " + newPath);
* }
*
* location.pathChangeRequired.connect(onPathChangeRequired);
*/
void pathChangeRequired(const QString& newPath);
/**jsdoc
* Triggered when you navigate to a new domain.
* @function location.hostChanged
* @param {string} hostname - The new domain's host name.
* @returns {Signal}
* @example <caption>Report when you navigate to a new domain.</caption>
* function onHostChanged(host) {
* print("Host changed to: " + host);
* }
*
* location.hostChanged.connect(onHostChanged);
*/
void hostChanged(const QString& newHost);
/**jsdoc
* Triggered when there's a change in whether or not there's a previous location that can be navigated to using
* {@link location.goBack|goBack}. (Reflects changes in the state of the "Goto" dialog's back arrow.)
* @function location.goBackPossible
* @param {boolean} isPossible - <code>true</code> if there's a previous location to navigate to, otherwise
* <code>false</code>.
* @returns {Signal}
* @example <caption>Report when ability to navigate back changes.</caption>
* function onGoBackPossible(isPossible) {
* print("Go back possible: " + isPossible);
* }
*
* location.goBackPossible.connect(onGoBackPossible);
*/
void goBackPossible(bool isPossible);
/**jsdoc
* Triggered when there's a change in whether or not there's a forward location that can be navigated to using
* {@link location.goForward|goForward}. (Reflects changes in the state of the "Goto" dialog's forward arrow.)
* @function location.goForwardPossible
* @param {boolean} isPossible - <code>true</code> if there's a forward location to navigate to, otherwise
* <code>false</code>.
* @returns {Signal}
* @example <caption>Report when ability to navigate forward changes.</caption>
* function onGoForwardPossible(isPossible) {
* print("Go forward possible: " + isPossible);
* }
*
* location.goForwardPossible.connect(onGoForwardPossible);
*/
void goForwardPossible(bool isPossible);
protected:

View file

@ -437,7 +437,7 @@ void NodeList::sendPendingDSPathQuery() {
QString pendingPath = _domainHandler.getPendingPath();
if (!pendingPath.isEmpty()) {
qCDebug(networking) << "Attemping to send pending query to DS for path" << pendingPath;
qCDebug(networking) << "Attempting to send pending query to DS for path" << pendingPath;
// this is a slot triggered if we just established a network link with a DS and want to send a path query
sendDSPathQuery(_domainHandler.getPendingPath());