new HydroRTCClient(clientName) → {Object}
class for the HydroRTC-Client system, initializer of required variables and event emitters
Parameters:
Name | Type | Description |
---|---|---|
clientName |
String |
- Source:
Returns:
- Clientside rendering
- Type
- Object
Members
objectCreationEvent
List of emitters used from client server and vice versa
- Source:
Methods
(static) addDataToDB(data, storeNameopt) → {null}
This method adds the provided data to the specified IndexedDB object store. If the data includes an ArrayBuffer, it converts it to a Blob before adding it to the store. The method also logs success or error messages based on the outcome of the addition operation.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Object | The data object to be added to the database. The object can include a |
||
storeName |
string |
<optional> |
'data' | The name of the object store where the data will be added. Defaults to 'data'. |
- Source:
Returns:
- This method does not return a value. It logs success or error messages to the console.
- Type
- null
Example
const client = new HydroRTCClient();
client.createDB('ClientB'); // Initializes the database
const data = {
id: 'unique-id',
data: new ArrayBuffer(8),
binaryData: new Uint8Array([1, 2, 3, 4])
};
client.addDataToDB(data, 'data');
// Output in console: "Data was correctly added to IndexedDB: unique-id"
// If an error occurs, it will be logged to the console.
(static) calculateThroughput(chunk) → {void|null}
Calculates the throughput of a data stream.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
chunk |
Object | The current chunk of data being sent. Properties
|
- Source:
Returns:
- Type
- void | null
Example
const client = new HydroRTCClient();
const chunk = {
offset: 0,
fileSize: 1024 * 1024, // 1 MB
isLastChunk: true
};
client.calculateThroughput(chunk);
(static) concatenateResults(arrayBuffers) → {ArrayBuffer}
This method takes an array of ArrayBuffer objects, calculates the total length required, and creates a new ArrayBuffer to hold the concatenated data. It copies the contents of each input ArrayBuffer into the new ArrayBuffer and returns it.
Parameters:
Name | Type | Description |
---|---|---|
arrayBuffers |
Array.<ArrayBuffer> | An array of ArrayBuffer objects to be concatenated. |
- Source:
Returns:
A new ArrayBuffer containing the concatenated data from all input ArrayBuffers.
- Type
- ArrayBuffer
Example
const client = new HydroRTCClient();
const arrayBuffer1 = new Uint8Array([1, 2, 3]).buffer;
const arrayBuffer2 = new Uint8Array([4, 5, 6]).buffer;
const concatenatedBuffer = client.concatenateResults([arrayBuffer1, arrayBuffer2]);
// concatenatedBuffer will be an ArrayBuffer with data [1, 2, 3, 4, 5, 6]
(static) connectPeer(peerName) → {Promise.<void>}
Connect a client with a specific peer
Parameters:
Name | Type | Description |
---|---|---|
peerName |
string | The name of the peer to connect to |
- Source:
Returns:
- A promise that resolves when the connection is established
- Type
- Promise.<void>
(static) connectWithPeer(remotePeerId) → {Promise.<function()>}
Create the connection between the two Peers.
Sets up callbacks that handle any events related to the connection and data received on it. Connects to a remote peer using the PeerJS connection.
Parameters:
Name | Type | Description |
---|---|---|
remotePeerId |
string | The ID of the remote peer to connect to. |
- Source:
Returns:
- A promise that resolves to the
dataExchangeEventHandler
function.
- Type
- Promise.<function()>
Example
const client = new HydroRTCClient();
client.connectWithPeer('remotePeerId')
.then((dataExchangeEventHandler) => {
// Use the dataExchangeEventHandler to handle data exchange events
});
(static) createDB(clientName) → {null}
Creator of the database per clientName
Parameters:
Name | Type | Description |
---|---|---|
clientName |
String |
- Source:
Returns:
- registers an IndexedDB store for the data to be saved
- Type
- null
Example
const client = new HydroRTCClient();
client.createDB('ClientA');
// Output in console: "IndexedDB ClientA opened successfully."
// Later in the code, you can use `client.db` to interact with the created IndexedDB instance.
(static) dataChunks(file, maxChunkSize) → {void}
Sends a file in chunks to a peer connection.
Parameters:
Name | Type | Description |
---|---|---|
file |
File | The file to be sent. |
maxChunkSize |
number | The maximum size of each chunk in bytes. |
- Source:
Returns:
- Type
- void
Example
const client = new HydroRTCClient();
const file = new File(['Hello, World!'], 'hello.txt', { type: 'text/plain' });
client.dataChunks(file, 1024);
(static) dataTypeReader(fileType) → {EventEmitter}
Initiates the retrieval of data types supported by the server.
Parameters:
Name | Type | Description |
---|---|---|
fileType |
string | The type of data file to retrieve the supported data types for. |
- Source:
Returns:
- An event emitter that emits the supported data types.
- Type
- EventEmitter
Example
const client = new HydroRTCClient();
const dataTypesEventHandler = client.dataTypeReader('hdf5');
dataTypesEventHandler.on('data', (dataTypes) => {
console.log(dataTypes);
});
(static) deleteDataFromDB(itemID, storeNameopt) → {Promise.<void>}
Deletes data from the IndexedDB store.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
itemID |
String | The ID of the item to be deleted. |
||
storeName |
string |
<optional> |
'data' | The name of the store from which data will be deleted. |
- Source:
Returns:
- A promise that resolves when the item is successfully deleted.
- Type
- Promise.<void>
Example
// Usage example:
deleteDataFromDB(123, 'storeName')
.then(() => {
console.log('Item deleted successfully.');
})
.catch((error) => {
console.error(error);
});
(static) deleteDB() → {Promise.<void>}
Deletes the IndexedDB database.
- Source:
Throws:
-
Throws an error if the IndexedDB database name is not specified.
- Type
- Error
Returns:
- A promise that resolves when the database is successfully deleted.
- Type
- Promise.<void>
Example
// Usage example:
deleteDB()
.then(() => {
console.log('IndexedDB database deleted successfully.');
})
.catch((error) => {
console.error(error);
});
(static) getAvailableDataTypes() → {Array.<string>}
Retrieves the available data types for the client
- Source:
Returns:
- The available data types
- Type
- Array.<string>
(static) getAvailableUsecases() → {Array.<string>}
Retrieves the available use cases for the client
- Source:
Returns:
- The available use cases
- Type
- Array.<string>
(static) getConfiguration() → {Object}
Retrieves the current configuration of the client
- Source:
Returns:
- The current configuration of the client
- Type
- Object
(static) getDataFromDB(storeNameopt) → {Promise.<Array.<Object>>}
This method retrieves all data from the specified object store in IndexedDB. If the data includes binary data stored as a Blob, it is converted into an ArrayBuffer. The method returns a promise that resolves with the processed data or rejects with an error message if any issues occur.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
storeName |
string |
<optional> |
'data' | The name of the object store to retrieve data from. Defaults to 'data'. |
- Source:
Throws:
-
Will reject the promise with an error message if IndexedDB is not initialized or if there is an error during the retrieval process.
- Type
- Error
Returns:
A promise that resolves to an array of objects stored in the object store. The data is processed to convert any binary data stored as a Blob into an ArrayBuffer.
- Type
- Promise.<Array.<Object>>
Example
const client = new HydroRTCClient();
client.createDB('ClientC'); // Initializes the database
client.getDataFromDB('data')
.then(data => {
console.log('Retrieved data:', data);
})
.catch(error => {
console.error('Error retrieving data:', error);
});
// Output: "Retrieved data: [/* array of objects
(static) getfileData(fileInput, chunkSizeopt) → {void}
Retrieves file data from an input element and sends it in chunks to a peer connection.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fileInput |
HTMLInputElement | The file input element to retrieve the file from. |
||
chunkSize |
number |
<optional> |
1 | The size of each chunk in megabytes. Default is 1 MB. |
- Source:
Returns:
- Type
- void
Example
const fileInput = document.getElementById('file-input');
const client = new HydroRTCClient();
client.getfileData(fileInput, 10); // Send file in 10 MB chunks
(static) getHDF5(dataPath) → {EventEmitter}
Initiates the retrieval of HDF5 data from the server.
Parameters:
Name | Type | Description |
---|---|---|
dataPath |
string | The path to the HDF5 data to retrieve. |
- Source:
Returns:
- An event emitter that emits the retrieved HDF5 data.
- Type
- EventEmitter
Example
const client = new HydroRTCClient();
const hdf5EventHandler = client.getHDF5('/path/to/hdf5/data');
hdf5EventHandler.on('data', (data) => {
console.log(data);
});
(static) getNetCDF(dataPath) → {EventEmitter}
Initiates the retrieval of netCDF data from the server.
Parameters:
Name | Type | Description |
---|---|---|
dataPath |
string | The path to the netCDF data to retrieve. |
- Source:
Returns:
- An event emitter that emits the retrieved netCDF data.
- Type
- EventEmitter
Example
const client = new HydroRTCClient();
const netCDFEventHandler = client.getNetCDF('/path/to/netcdf/data');
netCDFEventHandler.on('data', (data) => {
console.log(data);
});
(static) getPeers() → {function}
Retrieves the list of peers for the current client
- Source:
Returns:
- Event emitter for the peer listener
- Type
- function
(static) getPeersID(remotePeerId) → {function}
Retrieves the peer ID for the specified remote peer
Parameters:
Name | Type | Description |
---|---|---|
remotePeerId |
String | The ID of the remote peer |
- Source:
Returns:
- Event emitter for the peer listener
- Type
- function
(static) getTIFF(dataPath) → {EventEmitter}
Initiates the retrieval of TIFF data from the server.
Parameters:
Name | Type | Description |
---|---|---|
dataPath |
string | The path to the TIFF data to retrieve. |
- Source:
Returns:
- An event emitter that emits the retrieved TIFF data.
- Type
- EventEmitter
Example
const client = new HydroRTCClient();
const tiffEventHandler = client.getTIFF('/path/to/tiff/data');
tiffEventHandler.on('data', (data) => {
console.log(data);
});
(static) initPeerJSConn(propsopt) → {void}
Initializes the PeerJS connection for the HydroRTCClient.
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
props |
Object |
<optional> |
{} | Optional configuration properties for the PeerJS connection. Properties
|
- Source:
Returns:
- Type
- void
(static) listenRequests() → {function}
Enables the client to receive connection requests from other peers
- Source:
Returns:
- Event handler for the connection request
- Type
- function
(static) logout() → {Promise.<void>}
Logs out the user by deleting the IndexedDB database.
- Source:
Returns:
- A promise that resolves when the user is successfully logged out.
- Type
- Promise.<void>
Example
// Usage example:
logout()
.then(() => {
console.log('User logged out successfully.');
})
.catch((error) => {
console.error('Error during logout: ', error);
});
(static) receiveSmartData(dataPath, frequency, resolution) → {EventEmitter}
Initiates the reception of smart data from the server.
Parameters:
Name | Type | Description |
---|---|---|
dataPath |
string | The path to the smart data to receive. |
frequency |
number | The frequency at which to receive the smart data. |
resolution |
number | The resolution of the smart data. |
- Source:
Returns:
- An event emitter that emits the received smart data.
- Type
- EventEmitter
Example
const client = new HydroRTCClient();
const smartDataEventHandler = client.receiveSmartData('/path/to/data', 1000, 100);
smartDataEventHandler.on('data', (data) => {
console.log(data);
});
(static) receiveTask() → {EventEmitter}
Retrieves a task from the server.
- Source:
Returns:
- An event emitter that emits the task data.
- Type
- EventEmitter
Example
const client = new HydroRTCClient();
const taskDataEventHandler = client.receiveTask();
taskDataEventHandler.on('data', (taskData) => {
console.log(taskData);
});
(static) requestDataFromPeer(peerName, request) → {function}
Requests data from a specified peer
Parameters:
Name | Type | Description |
---|---|---|
peerName |
string | The name of the peer to request data from |
request |
Promise | The data request to be sent to the peer |
- Source:
Returns:
- The event handler for the data exchange
- Type
- function
(static) sendDataToPeer(data, usecaseopt) → {Promise.<void>}
Send data to a connected peer
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Object | The data to be sent to the peer |
||
usecase |
string |
<optional> |
'message' | The use case for the data being sent (default is 'message') |
- Source:
Returns:
- A promise that resolves when the data has been sent
- Type
- Promise.<void>
(static) setConfiguration(usecases, receiveDataTypes, sendDataTypes)
Configures the client's use cases and data types for sending and receiving
Parameters:
Name | Type | Description |
---|---|---|
usecases |
Array.<string> | The use cases to be enabled for the client |
receiveDataTypes |
Array.<string> | The data types the client can receive |
sendDataTypes |
Array.<string> | The data types the client can send |
- Source:
(static) socketEventHandlers() → {void}
This method initializes handlers for different socket events including user validation, data streams, peers, and file types. Each handler processes incoming data from the server and triggers the corresponding event handlers within the client.
- Source:
Returns:
- Type
- void
Example
const client = new HydroRTCClient();
client.socketEventHandlers();
// The socketEventHandlers method sets up handlers for events such as:
// - "valid-username": Handles validation of usernames.
// - "connect": Logs connection status.
// - "data-stream": Processes incoming data streams.
// - "peers": Manages peer lists.
// - "smart-data": Handles smart data streams.
// - "netcdf-data", "hdf5-data", "tiff-data": Handles different file types.
// - "datatype-files": Manages data type requests.
// - "connect-request": Manages peer connection requests.
// - "task": Handles tasks from the server.
// - "data-upload": Handles user data uploads.
// - "delete-db": Deletes the database and logs a message.
(static) streamDataRequest(filePath) → {EventEmitter|null}
This method requests streaming data from the server for a given file path. It resets the streamData
property to ensure that only one stream of data is handled at a time. If the client is eligible for the "stream-data" use case, it emits a "stream-data" event to the server with the client name, socket ID, and file path. The method returns an EventEmitter instance to handle the stream data events or null
if the client is not eligible.
Parameters:
Name | Type | Description |
---|---|---|
filePath |
string | The path to the file for which streaming data is requested. |
- Source:
Returns:
An EventEmitter instance for handling stream data events if the request is successful. Returns null
if the client is not eligible for the "stream-data" use case.
- Type
- EventEmitter | null
Example
const client = new HydroRTCClient();
const filePath = '/path/to/file';
const streamHandler = client.streamDataRequest(filePath);
if (streamHandler) {
streamHandler.on('data', (data) => {
console.log('Received stream data:', data);
});
} else {
console.log('Client is not eligible for stream-data use case.');
}
(static) submitTaskResult(task, result) → {void}
Submits the result of a task to the server.
Parameters:
Name | Type | Description |
---|---|---|
task |
object | The task object. |
result |
object | The result of the task. |
- Source:
Returns:
- Type
- void
Example
const client = new HydroRTCClient();
const task = { id: 1, description: 'Perform data analysis' };
const result = { analysis: 'The data shows a positive trend' };
client.submitTaskResult(task, result);
(static) updateSmartDataPriority(frequency, resolution) → {void}
Updates the priority of smart data sharing based on the specified frequency and resolution.
Parameters:
Name | Type | Description |
---|---|---|
frequency |
number | The desired frequency of data updates. |
resolution |
number | The desired resolution of the data. |
- Source:
Returns:
- Type
- void
Example
const client = new HydroRTCClient();
client.updateSmartDataPriority(1000, 10);