-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
Conversation
test |
lib/definitions/livesync.d.ts
Outdated
* @param configuration - The configuration to the socket connection. | ||
* @returns {Promise<void>} | ||
*/ | ||
connect(configuration: ILivesyncToolConfiguration): Promise<void>; |
There was a problem hiding this comment.
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; })); |
There was a problem hiding this comment.
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; ));
There was a problem hiding this comment.
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[]> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this 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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.`); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
1b5dfae
to
f81fc16
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After green build!
test |
await this.doSync(liveSyncInfo, false); | ||
} | ||
|
||
private async doSync(liveSyncInfo: ILiveSyncResultInfo, doRefresh = false): Promise<IAndroidLivesyncSyncOperationResult> { |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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 };
…to {N} CLI and fix lint errors
09b4db5
to
5ffaba7
Compare
Implements #3797 |
PR Checklist
The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/CONTRIBUTING.md#commit-messages.
There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it.
You have signed the CLA.
All existing tests are passing: https://github.com/NativeScript/nativescript-cli/blob/master/CONTRIBUTING.md#contribute-to-the-code-base
Tests for the changes are included. - will be written during review
Add README.md for Public API of androidLivesyncLibrary
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