{"action":"created","comment":{"url":"https://api.github.com/repos/appcelerator/androidlib/pulls/comments/57968286","id":57968286,"diff_hunk":"@@ -0,0 +1,282 @@\n+import { EventEmitter } from 'events';\n+import * as net from 'net';\n+\n+let connCounter = 0;\n+\n+/**\n+ * @constant\n+ * Initial state. Also set if a command fails or the connection is closed.\n+ */\n+const DO_NOTHING = 0;\n+\n+/**\n+ * @constant\n+ * After a command is executed, this will wait for the OKAY/FAIL response.\n+ */\n+const WAIT_FOR_COMMAND_RESULT = 1;\n+\n+/**\n+ * @constant\n+ * After a command executes and we have received the OKAY/FAIL, then we process\n+ * whatever data is left. Certain commands, such as track-devices, keep sending\n+ * more data that begins with the length of data expected.\n+ */\n+const WAIT_FOR_NEW_DATA = 2;\n+\n+/**\n+ * @constant\n+ * After a command is executed, this will wait for additional data until the\n+ * connection is closed. This is for \"adb shell\" commands where the exact\n+ * output length is unknown.\n+ */\n+const BUFFER_UNTIL_CLOSE = 3;\n+\n+/**\n+ * Creates an Connection instance.\n+ *\n+ * @class\n+ * @extends EventEmitter\n+ * @classdesc Manages the connection and communcations with the ADB server.\n+ * @constructor\n+ * @param {ADB} adb - The ADB instance.\n+ */\n+export class Connection extends EventEmitter {\n+\tconstructor(adb) {\n+\t\tsuper();\n+\t\tthis.adb = adb;\n+\t\tthis.port = adb && adb.opts && adb.opts.port || 5037;\n+\t\tthis.socket = null;\n+\t\tthis.state = DO_NOTHING;\n+\t\tthis.connNum = ++connCounter;\n+\t\tthis.dataEventName = 'data';\n+\t\tthis.endEventName = 'end';\n+\t}\n+\n+\t/**\n+\t * Executes a command. If there is no connection to the ADB server, it will\n+\t * connect to it, then run the command.\n+\t *\n+\t * @param {String} cmd - The command to run.\n+\t * @param {Object} [opts] - Execute options.\n+\t * @param {Boolean} [opts.bufferUntilClose=false] - Buffers all received data until ADB closes the connection.\n+\t * @returns {Promise}\n+\t * @access public\n+\t */\n+\texec(cmd, opts = {}) {\n+\t\tif (typeof cmd !== 'string' || !cmd) {\n+\t\t\treturn Promise.reject(new TypeError('Expected command to be a string.'));\n+\t\t}\n+\n+\t\tconst dataEventName = this.dataEventName;\n+\t\treturn new Promise((resolve, reject) => {\n+\t\t\tlet conn = this;","path":"src/connection.js","position":72,"original_position":72,"commit_id":"c8c61b9a8f556f4454931f09afedac87dc7cf22d","original_commit_id":"c8c61b9a8f556f4454931f09afedac87dc7cf22d","user":{"login":"cb1kenobi","id":97262,"avatar_url":"https://avatars.githubusercontent.com/u/97262?v=3","gravatar_id":"","url":"https://api.github.com/users/cb1kenobi","html_url":"https://github.com/cb1kenobi","followers_url":"https://api.github.com/users/cb1kenobi/followers","following_url":"https://api.github.com/users/cb1kenobi/following{/other_user}","gists_url":"https://api.github.com/users/cb1kenobi/gists{/gist_id}","starred_url":"https://api.github.com/users/cb1kenobi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cb1kenobi/subscriptions","organizations_url":"https://api.github.com/users/cb1kenobi/orgs","repos_url":"https://api.github.com/users/cb1kenobi/repos","events_url":"https://api.github.com/users/cb1kenobi/events{/privacy}","received_events_url":"https://api.github.com/users/cb1kenobi/received_events","type":"User","site_admin":false},"body":"No need to assign `this` to a local variable. Just use `this.*` instead of `conn.*`.","created_at":"2016-03-30T21:37:02Z","updated_at":"2016-03-30T21:37:02Z","html_url":"https://github.com/appcelerator/androidlib/pull/5#discussion_r57968286","pull_request_url":"https://api.github.com/repos/appcelerator/androidlib/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/comments/57968286"},"html":{"href":"https://github.com/appcelerator/androidlib/pull/5#discussion_r57968286"},"pull_request":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/appcelerator/androidlib/pulls/5","id":63779849,"html_url":"https://github.com/appcelerator/androidlib/pull/5","diff_url":"https://github.com/appcelerator/androidlib/pull/5.diff","patch_url":"https://github.com/appcelerator/androidlib/pull/5.patch","issue_url":"https://api.github.com/repos/appcelerator/androidlib/issues/5","number":5,"state":"open","locked":false,"title":"[TIMOB-20327] Androidlib: android environment detection","user":{"login":"feons","id":7485592,"avatar_url":"https://avatars.githubusercontent.com/u/7485592?v=3","gravatar_id":"","url":"https://api.github.com/users/feons","html_url":"https://github.com/feons","followers_url":"https://api.github.com/users/feons/followers","following_url":"https://api.github.com/users/feons/following{/other_user}","gists_url":"https://api.github.com/users/feons/gists{/gist_id}","starred_url":"https://api.github.com/users/feons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feons/subscriptions","organizations_url":"https://api.github.com/users/feons/orgs","repos_url":"https://api.github.com/users/feons/repos","events_url":"https://api.github.com/users/feons/events{/privacy}","received_events_url":"https://api.github.com/users/feons/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-22T19:35:57Z","updated_at":"2016-03-30T21:37:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f8483fc43ea39a1a0cfdcadd06a395d62fc4178c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/appcelerator/androidlib/pulls/5/commits","review_comments_url":"https://api.github.com/repos/appcelerator/androidlib/pulls/5/comments","review_comment_url":"https://api.github.com/repos/appcelerator/androidlib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/appcelerator/androidlib/issues/5/comments","statuses_url":"https://api.github.com/repos/appcelerator/androidlib/statuses/c8c61b9a8f556f4454931f09afedac87dc7cf22d","head":{"label":"feons:timob-20327-init","ref":"timob-20327-init","sha":"c8c61b9a8f556f4454931f09afedac87dc7cf22d","user":{"login":"feons","id":7485592,"avatar_url":"https://avatars.githubusercontent.com/u/7485592?v=3","gravatar_id":"","url":"https://api.github.com/users/feons","html_url":"https://github.com/feons","followers_url":"https://api.github.com/users/feons/followers","following_url":"https://api.github.com/users/feons/following{/other_user}","gists_url":"https://api.github.com/users/feons/gists{/gist_id}","starred_url":"https://api.github.com/users/feons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feons/subscriptions","organizations_url":"https://api.github.com/users/feons/orgs","repos_url":"https://api.github.com/users/feons/repos","events_url":"https://api.github.com/users/feons/events{/privacy}","received_events_url":"https://api.github.com/users/feons/received_events","type":"User","site_admin":false},"repo":{"id":51876785,"name":"androidlib","full_name":"feons/androidlib","owner":{"login":"feons","id":7485592,"avatar_url":"https://avatars.githubusercontent.com/u/7485592?v=3","gravatar_id":"","url":"https://api.github.com/users/feons","html_url":"https://github.com/feons","followers_url":"https://api.github.com/users/feons/followers","following_url":"https://api.github.com/users/feons/following{/other_user}","gists_url":"https://api.github.com/users/feons/gists{/gist_id}","starred_url":"https://api.github.com/users/feons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feons/subscriptions","organizations_url":"https://api.github.com/users/feons/orgs","repos_url":"https://api.github.com/users/feons/repos","events_url":"https://api.github.com/users/feons/events{/privacy}","received_events_url":"https://api.github.com/users/feons/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/feons/androidlib","description":"Android Utility Library","fork":true,"url":"https://api.github.com/repos/feons/androidlib","forks_url":"https://api.github.com/repos/feons/androidlib/forks","keys_url":"https://api.github.com/repos/feons/androidlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/feons/androidlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/feons/androidlib/teams","hooks_url":"https://api.github.com/repos/feons/androidlib/hooks","issue_events_url":"https://api.github.com/repos/feons/androidlib/issues/events{/number}","events_url":"https://api.github.com/repos/feons/androidlib/events","assignees_url":"https://api.github.com/repos/feons/androidlib/assignees{/user}","branches_url":"https://api.github.com/repos/feons/androidlib/branches{/branch}","tags_url":"https://api.github.com/repos/feons/androidlib/tags","blobs_url":"https://api.github.com/repos/feons/androidlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/feons/androidlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/feons/androidlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/feons/androidlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/feons/androidlib/statuses/{sha}","languages_url":"https://api.github.com/repos/feons/androidlib/languages","stargazers_url":"https://api.github.com/repos/feons/androidlib/stargazers","contributors_url":"https://api.github.com/repos/feons/androidlib/contributors","subscribers_url":"https://api.github.com/repos/feons/androidlib/subscribers","subscription_url":"https://api.github.com/repos/feons/androidlib/subscription","commits_url":"https://api.github.com/repos/feons/androidlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/feons/androidlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/feons/androidlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/feons/androidlib/issues/comments{/number}","contents_url":"https://api.github.com/repos/feons/androidlib/contents/{+path}","compare_url":"https://api.github.com/repos/feons/androidlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/feons/androidlib/merges","archive_url":"https://api.github.com/repos/feons/androidlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/feons/androidlib/downloads","issues_url":"https://api.github.com/repos/feons/androidlib/issues{/number}","pulls_url":"https://api.github.com/repos/feons/androidlib/pulls{/number}","milestones_url":"https://api.github.com/repos/feons/androidlib/milestones{/number}","notifications_url":"https://api.github.com/repos/feons/androidlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/feons/androidlib/labels{/name}","releases_url":"https://api.github.com/repos/feons/androidlib/releases{/id}","deployments_url":"https://api.github.com/repos/feons/androidlib/deployments","created_at":"2016-02-16T22:58:18Z","updated_at":"2016-02-16T22:58:19Z","pushed_at":"2016-03-30T03:40:38Z","git_url":"git://github.com/feons/androidlib.git","ssh_url":"git@github.com:feons/androidlib.git","clone_url":"https://github.com/feons/androidlib.git","svn_url":"https://github.com/feons/androidlib","homepage":null,"size":106,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"appcelerator:timob-20327","ref":"timob-20327","sha":"29c2a0487a6c1627b68c1a3ded0a20b02b48d0f9","user":{"login":"appcelerator","id":82188,"avatar_url":"https://avatars.githubusercontent.com/u/82188?v=3","gravatar_id":"","url":"https://api.github.com/users/appcelerator","html_url":"https://github.com/appcelerator","followers_url":"https://api.github.com/users/appcelerator/followers","following_url":"https://api.github.com/users/appcelerator/following{/other_user}","gists_url":"https://api.github.com/users/appcelerator/gists{/gist_id}","starred_url":"https://api.github.com/users/appcelerator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appcelerator/subscriptions","organizations_url":"https://api.github.com/users/appcelerator/orgs","repos_url":"https://api.github.com/users/appcelerator/repos","events_url":"https://api.github.com/users/appcelerator/events{/privacy}","received_events_url":"https://api.github.com/users/appcelerator/received_events","type":"Organization","site_admin":false},"repo":{"id":20471433,"name":"androidlib","full_name":"appcelerator/androidlib","owner":{"login":"appcelerator","id":82188,"avatar_url":"https://avatars.githubusercontent.com/u/82188?v=3","gravatar_id":"","url":"https://api.github.com/users/appcelerator","html_url":"https://github.com/appcelerator","followers_url":"https://api.github.com/users/appcelerator/followers","following_url":"https://api.github.com/users/appcelerator/following{/other_user}","gists_url":"https://api.github.com/users/appcelerator/gists{/gist_id}","starred_url":"https://api.github.com/users/appcelerator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appcelerator/subscriptions","organizations_url":"https://api.github.com/users/appcelerator/orgs","repos_url":"https://api.github.com/users/appcelerator/repos","events_url":"https://api.github.com/users/appcelerator/events{/privacy}","received_events_url":"https://api.github.com/users/appcelerator/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/appcelerator/androidlib","description":"Android Utility Library","fork":false,"url":"https://api.github.com/repos/appcelerator/androidlib","forks_url":"https://api.github.com/repos/appcelerator/androidlib/forks","keys_url":"https://api.github.com/repos/appcelerator/androidlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/appcelerator/androidlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/appcelerator/androidlib/teams","hooks_url":"https://api.github.com/repos/appcelerator/androidlib/hooks","issue_events_url":"https://api.github.com/repos/appcelerator/androidlib/issues/events{/number}","events_url":"https://api.github.com/repos/appcelerator/androidlib/events","assignees_url":"https://api.github.com/repos/appcelerator/androidlib/assignees{/user}","branches_url":"https://api.github.com/repos/appcelerator/androidlib/branches{/branch}","tags_url":"https://api.github.com/repos/appcelerator/androidlib/tags","blobs_url":"https://api.github.com/repos/appcelerator/androidlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/appcelerator/androidlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/appcelerator/androidlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/appcelerator/androidlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/appcelerator/androidlib/statuses/{sha}","languages_url":"https://api.github.com/repos/appcelerator/androidlib/languages","stargazers_url":"https://api.github.com/repos/appcelerator/androidlib/stargazers","contributors_url":"https://api.github.com/repos/appcelerator/androidlib/contributors","subscribers_url":"https://api.github.com/repos/appcelerator/androidlib/subscribers","subscription_url":"https://api.github.com/repos/appcelerator/androidlib/subscription","commits_url":"https://api.github.com/repos/appcelerator/androidlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/appcelerator/androidlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/appcelerator/androidlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/appcelerator/androidlib/issues/comments{/number}","contents_url":"https://api.github.com/repos/appcelerator/androidlib/contents/{+path}","compare_url":"https://api.github.com/repos/appcelerator/androidlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/appcelerator/androidlib/merges","archive_url":"https://api.github.com/repos/appcelerator/androidlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/appcelerator/androidlib/downloads","issues_url":"https://api.github.com/repos/appcelerator/androidlib/issues{/number}","pulls_url":"https://api.github.com/repos/appcelerator/androidlib/pulls{/number}","milestones_url":"https://api.github.com/repos/appcelerator/androidlib/milestones{/number}","notifications_url":"https://api.github.com/repos/appcelerator/androidlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/appcelerator/androidlib/labels{/name}","releases_url":"https://api.github.com/repos/appcelerator/androidlib/releases{/id}","deployments_url":"https://api.github.com/repos/appcelerator/androidlib/deployments","created_at":"2014-06-04T05:34:26Z","updated_at":"2015-03-12T20:20:00Z","pushed_at":"2016-03-30T03:40:39Z","git_url":"git://github.com/appcelerator/androidlib.git","ssh_url":"git@github.com:appcelerator/androidlib.git","clone_url":"https://github.com/appcelerator/androidlib.git","svn_url":"https://github.com/appcelerator/androidlib","homepage":null,"size":62,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":1,"forks":4,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/5"},"html":{"href":"https://github.com/appcelerator/androidlib/pull/5"},"issue":{"href":"https://api.github.com/repos/appcelerator/androidlib/issues/5"},"comments":{"href":"https://api.github.com/repos/appcelerator/androidlib/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/appcelerator/androidlib/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/appcelerator/androidlib/statuses/c8c61b9a8f556f4454931f09afedac87dc7cf22d"}}}}