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

First exchange of Vircadia protocol packets with the Domain server. #9

Merged
merged 25 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b8f179b
Housekeeping
ctrlaltdavid Jun 8, 2021
7d1833d
Merge remote-tracking branch 'upstream/master' into dev/webrtc-packet
ctrlaltdavid Jun 11, 2021
1276d92
assert utility function
ctrlaltdavid Jun 11, 2021
a3e6cf6
Uuid class and type
ctrlaltdavid Jun 11, 2021
499dbfb
Signal class emulating Qt's signals and slots mechanism
ctrlaltdavid Jun 11, 2021
e149184
Revise NodeType namespace implementation
ctrlaltdavid Jun 11, 2021
ea2d6bb
PacketType namespace and type
ctrlaltdavid Jun 11, 2021
b95d341
HifiSockAddr class
ctrlaltdavid Jun 11, 2021
aebc09d
Tidying
ctrlaltdavid Jun 17, 2021
ba2193a
General packet and message-related classes
ctrlaltdavid Jun 18, 2021
5256ee5
DataView extensions for reading/writing unsigned 128-bit BigInt values
ctrlaltdavid Jun 18, 2021
202ac33
DomainConnectRequest and DomainList packets
ctrlaltdavid Jun 19, 2021
22ea6ea
AddressManager, DomainHandler, and PacketReceiver
ctrlaltdavid Jun 20, 2021
58e0e8c
NodesList and LimitedNodeList
ctrlaltdavid Jun 20, 2021
eda15b1
Tidying
ctrlaltdavid Jun 20, 2021
2ad12fc
Typos
ctrlaltdavid Jun 27, 2021
08fa448
Update protocol signature
ctrlaltdavid Jun 27, 2021
bc054f6
Tidying
ctrlaltdavid Jun 30, 2021
2a34c0c
Socket and WebRTCSocket
ctrlaltdavid Jun 30, 2021
d359813
Tidying
ctrlaltdavid Jun 30, 2021
9845ef7
Fix license typo
ctrlaltdavid Jul 6, 2021
b3338d3
Add tests configuration file
ctrlaltdavid Jul 6, 2021
a914bf4
Misc. CR changes
ctrlaltdavid Jul 6, 2021
287dedf
Add missing JSDoc
ctrlaltdavid Jul 6, 2021
31718f4
Linting
ctrlaltdavid Jul 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ module.exports = {
"nonwords": false
}
],
"spaced-comment": "error",
"spaced-comment": ["error", "always", { "exceptions": ["@devdoc", "@sdkdoc"] }],
"switch-colon-spacing": "error",
"template-tag-spacing": "error",
"unicode-bom": "error",
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,24 @@ npm run build
npm run lint
```

### Run unit tests
### Run tests

All tests:
```
npm run test
```
Hot retest
Hot retest of all tests:
```
npm run test-watch
```

Specific tests (e.g., Packet.unit.test.js, all unit tests):
```
npm run test /packet.unit
npm run test unit.test
```


### Generate docs

SDK documentation:
Expand Down
12 changes: 7 additions & 5 deletions src/Vircadia.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
// Created by David Rowe on 9 May 2021.
// Copyright 2021 Vircadia contributors.
//
// Distributed under the Apache License", Version 2.0.
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//

/*@sdkdoc
* This is the Vircadia SDK.
* @namespace Vircadia
* This is the Vircadia SDK.
* <p>C++: This abstracts out key components of the native Vircadia Interface app.</p>
*
* @namespace Vircadia
*/
const Vircadia = (function () {

/**
* Says hello to the world.
* @function Vircadia.helloWorld
* Says hello to the world.
* @function Vircadia.helloWorld
*/
function helloWorld() {
console.log("Hello world!");
Expand Down
86 changes: 86 additions & 0 deletions src/libraries/networking/AddressManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// AddressManager.js
//
// Created by David Rowe on 6 Jun 2021.
// Copyright 2021 Vircadia contributors.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//

import Signal from "../shared/Signal.js";
import Uuid from "../shared/Uuid.js";


/*@devdoc
* Manages your current location in the metaverse.
* <p>C++: <code>AddressManager : public QObject, public Dependency</code></p>
* @namespace AddressManager
*/
const AddressManager = new (class {
// C++ AddressManager : public QObject, public Dependency

#_domainUrl = Uuid.NULL;
#_possibleDomainChangeRequired = new Signal();

#handlerUrl(url) {
// C++ bool handleUrl(const QUrl& lookupUrl, LookupTrigger trigger = UserInput)

// WEBRTC TODO: Address further C++ code.

this.#_domainUrl = url;
this.#_possibleDomainChangeRequired.emit(this.#_domainUrl, Uuid.NULL);

// WEBRTC TODO: Address further C++ code.

return true;
}

/*@devdoc
* Takes you to a specified metaverse address.
* @function AddressManager.handleLookupString
* @param {string} address - The address to go to.
* @param {boolean} [from=false] - Set to <code>true</code> if the address is obtained from the "Explore" app. Helps ensure
* that the user's location history is correctly maintained.
*/
handleLookupString(address) {
// C++ void handleLookupString(const QString& lookupString, bool fromSuggestions = false)

// WEBRTC TODO: Address further C++ code.

const sanitizedAddress = address.trim();
if (sanitizedAddress.length > 0) {
this.#handlerUrl(sanitizedAddress);
}

// WEBRTC TODO: Address further C++ code.
}

/*@devdoc
* Gets the domain's place name.
* @function AddressManager.getPlaceName
* @returns {string} The domain's place name if known, otherwise <code>""</code>.
*/
getPlaceName() { // eslint-disable-line class-methods-use-this
// C++ QString getPlaceName()

// WEBRTC TODO: Address further C++ code.

return "";
}

/*@devdoc
* Triggered when a request is made to go to a URL or IP address.
* @function AddressManager.possibleDomainChangeRequired
* @param {string} url - The domain address.
* @param {Uuid} id - The domain ID. May be {@link Uuid(1)|Uuid.NULL} if not yet known.
* @returns {Signal}
*/
get possibleDomainChangeRequired() {
// C++ void possibleDomainChangeRequired(QUrl domainURL, QUuid domainID);
return this.#_possibleDomainChangeRequired;
}

})();

export default AddressManager;
210 changes: 210 additions & 0 deletions src/libraries/networking/DomainHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
//
// DomainHandler.js
//
// Created by David Rowe on 5 Jun 2021.
// Copyright 2021 Vircadia contributors.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//

import HifiSockAddr from "./HifiSockAddr.js";
import Signal from "../shared/Signal.js";
import Uuid from "../shared/Uuid.js";


/*@devdoc
* Handles the connection to and the features of a domain.
* <p>C++: <code>DomainHandler : QObject</code></p>
* @class DomainHandler
*/
class DomainHandler {
// C++ DomainHandler

#_domainURL = null;
#_sockAddr = new HifiSockAddr(); // For WebRTC, the port is the critical part.
#_isConnected = false;
#_localID = 0;
#_uuid = Uuid.NULL;

#_connectedToDomain = new Signal();
#_disconnectedFromDomain = new Signal();


constructor() {

// Set up slots.
this.setURLAndID = this.setURLAndID.bind(this);

// WEBRTC TODO: Address further C++ code.

}

/*@devdoc
* Sets the domain's UUID.
* @param {Uuid} uuid - The domain's UUID.
*/
setUUID(uuid) {
// C++ void setUUID(const QUuid& uuid)
this.#_uuid = uuid;

// WEBRTC TODO: Address further C++ code.
}

/*@devdoc
* Gets the domain's UUID.
* @returns {Uuid} The domain's UUID.
*/
getUUID() {
// C++ QUuid& getUUID()
return this.#_uuid;
}

/*@devdoc
* Sets the domain's local ID.
* @param {LocalID} localID - The domain's local ID.
*/
setLocalID(localID) {
// C++ void setLocalID(LocalID localID)
this.#_localID = localID;
}

/*@devdoc
* Gets the domain's local ID.
* @returns {LocalID} The domain's local ID.
*/
getLocalID() {
// C++ LocalID getLocalID()
return this.#_localID;
}

/*@devdoc
* Gets the current domain's URL. <em>JavaScript-specific method.</em>
* <p>Note: The web app uses the domain's URL rather than its IP address.<p>
* @returns {string} The current domain's URL.
*/
getURL() {
// C++ WebRTC-specific method.

// WEBRTC TODO: Revisit using URL versus IP address..

return this.#_domainURL;
}

/*@devdoc
* Gets the domain's address.
* @returns {HifiSockAddr} The domain's address.
*/
getSockAddr() {
// C++ HifiSockAddr& getSockAddr()
return this.#_sockAddr;
}

/*@devdoc
* Sets the domain's network port.
* @param {number} port - The domain's network port.
*/
setPort(port) {
// C++ void setPort(quint16 port)
this.#_sockAddr.setPort(port);
}

/*@devdoc
* Gets the domain's network port.
* @returns {number} The domain's network port.
*/
getPort() {
// C++ unsigned short getPort()
return this.#_sockAddr.getPort();
}

/*@devdoc
* Gets whether Interface is connected to the domain.
* @returns {boolean} <code>true</code> if connect to the domain, <code>false</code> if not connected.
*/
isConnected() {
// C++ bool isConnected()
return this.#_isConnected;
}

/*@devdoc
* Sets whether Interface is connected to the domain.
* @param {boolean} isConnected - <code>true</code> if Interface is connected to the domain, <code>false</code> if it
* isn't.
*/
setIsConnected(isConnected) {
// C++ void setIsConnected(bool isConnected)
if (this.#_isConnected !== isConnected) {
this.#_isConnected = isConnected;
if (this.#_isConnected) {

// WEBRTC TODO: Address further C++ code.

this.connectedToDomain.emit(this.#_domainURL);

// WEBRTC TODO: Address further C++ code.

} else {
this.disconnectedFromDomain.emit();
}
}
}

/*@devdoc
* Gets whether Interface's connection to the domain server has timed out &mdash; it hasn't been responding to
* DomainConnectRequest and DomainListRequest packets for a while.
* @returns {boolean} <code>true</code> if Interface's connection to the domain server has timed out, <code>false</code> if
* it hasn't.
*/
// eslint-disable-next-line class-methods-use-this
checkInPacketTimeout() {
// C++ bool checkInPacketTimeout()

// WEBRTC TODO: Address further C++ code. And add an integration test.

return false;
}


/*@devdoc
* Sets the current domain's URL and pending ID.
* @function DomainHandler.setURLAndID
* @param {string} url - The domain's URL.
* @param {Uuid} id - The domain's pending ID.
* @returns {Slot}
*/
setURLAndID(url, id) { // eslint-disable-line
// C++ void setURLAndID(QUrl domainURL, QUuid domainID)

// WEBRTC TODO: Address further C++ code.

this.#_domainURL = url;

// WEBRTC TODO: Address further C++ code.
}


/*@devdoc
* Triggered when Interface connects to then domain.
* @function DomainHandler.connectedToDomain
* @param {string} domainURL - The domain's URL.
* @returns {Signal}
*/
get connectedToDomain() {
// C++ void connectedToDomain(QUrl domainURL)
return this.#_connectedToDomain;
}

/*@devdoc
* Triggered when Interface disconnects from the domain.
* @function DomainHandler.disconnectedFromDomain
* @returns {Signal}
*/
get disconnectedFromDomain() {
// C++ void disconnectedFromDomain()
return this.#_disconnectedFromDomain;
}

}

export default DomainHandler;
Loading