Skip to content

Kddimitrov/android livesync sockets #3746

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

Merged
merged 22 commits into from
Jul 24, 2018

Conversation

KristianDD
Copy link
Contributor

@KristianDD KristianDD commented Jul 12, 2018

PR Checklist

What is the current behavior?

Currently all files are transferred to the file system of the deice

What is the new behavior?

All files are transferred directly though the socket

Will log issue in CLI
Runtime issue: NativeScript/android#932

@dtopuzov
Copy link
Contributor

test

@Natalia-Hristova Natalia-Hristova added this to the 4.2.0 milestone Jul 16, 2018
* @param configuration - The configuration to the socket connection.
* @returns {Promise<void>}
*/
connect(configuration: ILivesyncToolConfiguration): Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be IAndroidLivesyncToolConfiguration

}

public async removeFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void> {
await this.livesyncTool.removeFiles(_.map(localToDevicePaths, (element: any) => { return element.filePath; }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return this.livesyncTool.removeFiles(_.map(localToDevicePaths, (element: any) => element.filePath; ));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or even the _.map(users, 'filePath') shorthand as we are already using any here.

return transferredFiles;
}

private async _transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deviceAppData: Mobile.IDeviceAppData parameter is not used inside the function, so we can remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same for projectFilesPath parameter

private async _transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> {
await this.livesyncTool.sendFiles(localToDevicePaths.map(localToDevicePathData => localToDevicePathData.getLocalPath()));

return localToDevicePaths;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need here to return the all passed file paths or we need to return all transferred files?

Copy link
Contributor

@DimitarTachev DimitarTachev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can also cover most of the story with unit tests.

if (this.isOperationInProgress(id)) {
this.handleSocketError(socketId, "Sync operation is taking too long");
}
}, 60000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

60000 -> const

* Checks if the current operation is in progress.
* @param operationId - The identifier of the operation.
*/
isOperationInProgress(operationId: string): boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we handle the timeouts and the logging using just the sendDoSyncOperation promise without the generateOperationIdentifier and isOperationInProgress?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible, but won't look good. As Promise has no property/method to check its state we have to attach to both resolve/reject and raise a local flag to indicate the state inside the interval function. It is again my personal preference to have the library provide the functionality.

/**
* Closes the current socket connection.
*/
end(): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the opposite of the connect method? It could be disconnect instead of end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason is the Socket API where the methods are actually connect and end. There is still a destroy method, but its used when an exception happened - reference.


interface IAndroidLivesyncToolConfiguration {
/**
* The application identifier.
Copy link
Contributor

@DimitarTachev DimitarTachev Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a rule for commenting а self-documented code? I don't see any additional value from such comments.

}

public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
const canExecuteFastSync = !liveSyncInfo.isFullSync && !_.some(liveSyncInfo.modifiedFilesData,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract the second part of the condition to a method for readability


setTimeout(() => {
if (!isResolved) {
isResolved = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isResolved -> isComplete in order to avoidisResolved = true when rejected?

for (const filePath of filePaths) {
if (this.$fs.getLsStats(filePath).isFile()) {
if (!this.$fs.exists(filePath)) {
this.$errors.fail(`${filePath} doesn't exist.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fail -> failWithoutHelp?

} else {
const error = this.checkConnectionStatus();
//TODO Destroy method added in node 8.0.0.
//when we depricate node 6.x uncoment the line belolw
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use something like process.version and a semver check?

Copy link
Contributor Author

@KristianDD KristianDD Jul 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think it`s worth the effort, given we will make older node versions unsupported not that far in the future.

import { AndroidDeviceHashService } from "../../common/mobile/android/android-device-hash-service";
import { DeviceLiveSyncServiceBase } from "./device-livesync-service-base";
import { APP_FOLDER_NAME } from "../../constants";
import { AndroidLivesyncTool } from "./android-livesync-library";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unify the class name and the file name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rosen-vladimirov @Fatme which one do you prefer - changing the file name or changing the interfaces and variables?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think changing the file name is better.


public end() {
if (this.socketConnection) {
this.socketConnection.end();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also set socketConnection to null and allow a new connect call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will happen in the close event callback.

@KristianDD KristianDD force-pushed the kddimitrov/android-livesync-sockets branch from 1b5dfae to f81fc16 Compare July 18, 2018 09:00
Copy link
Contributor

@Fatme Fatme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After green build!

@dtopuzov
Copy link
Contributor

test

await this.doSync(liveSyncInfo, false);
}

private async doSync(liveSyncInfo: ILiveSyncResultInfo, doRefresh = false): Promise<IAndroidLivesyncSyncOperationResult> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a good practice to add boolean variable.
Use dictionary instead:

doSync(liveSyncInfo, { doRefresh: false })

let result;
const operationId = this.livesyncTool.generateOperationIdentifier();

result = {operationId, didRefresh: true };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let result = {operationId, didRefresh: true };

@KristianDD KristianDD force-pushed the kddimitrov/android-livesync-sockets branch from 09b4db5 to 5ffaba7 Compare July 24, 2018 07:33
@KristianDD KristianDD merged commit 40201cb into master Jul 24, 2018
@rosen-vladimirov
Copy link
Contributor

Implements #3797

@KristianDD KristianDD deleted the kddimitrov/android-livesync-sockets branch November 21, 2018 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants