{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/comments/62283631","id":62283631,"diff_hunk":"@@ -0,0 +1,395 @@\n+/* This Source Code Form is subject to the terms of the Mozilla Public\n+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,\n+ * You can obtain one at http://mozilla.org/MPL/2.0/. */\n+\n+/*\n+ * RemoteControlService.jsm is the entry point of remote control function.\n+ * The service initializes a TLS socket server to receives events from user.\n+ *\n+ *               RemoteControlService <-- Gecko Preference\n+ *\n+ *     user -->  nsITLSSocketServer --> script (gecko)\n+ *\n+ * Events from user are in JSON format. After parsed to control command,\n+ * these events are passed to script (js), runs in sandbox,\n+ * and dispatch corresponding events to Gecko.\n+ *\n+ * Here is related component location:\n+ * gecko/b2g/components/RemoteControlService.jsm\n+ *\n+ * For more details, please visit: https://wiki.mozilla.org/Firefox_OS/Remote_Control\n+ */\n+\n+\"use strict\";\n+\n+this.EXPORTED_SYMBOLS = [\"RemoteControlService\"];\n+\n+const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu, Constructor: CC } = Components;\n+\n+Cu.import(\"resource://gre/modules/Services.jsm\");\n+Cu.import(\"resource://gre/modules/XPCOMUtils.jsm\");\n+Cu.import(\"resource://gre/modules/debug.js\");\n+\n+XPCOMUtils.defineLazyServiceGetter(this, \"certService\", \"@mozilla.org/security/local-cert-service;1\",\n+                                   \"nsILocalCertService\");\n+\n+// static functions\n+function debug(aStr) {\n+  dump(\"RemoteControlService: \" + aStr + \"\\n\");\n+}\n+\n+const DEBUG = false;\n+\n+const REMOTE_CONTROL_EVENT = 'mozChromeRemoteControlEvent';\n+const RC_PREF_DEVICES = \"remotecontrol.authorized_devices\";\n+const MAX_CLIENT_CONNECTIONS = 5; // Allow max 5 clients to use remote control TV\n+\n+const SERVER_STATUS = {\n+  STOPPED: 0,\n+  STARTED: 1\n+};\n+\n+this.RemoteControlService = {\n+  // Remote Control status\n+  _serverStatus: SERVER_STATUS.STOPPED,\n+\n+  // TLS socket server\n+  _port: -1, // The port on which this service listens\n+  _socket: null, // The socket associated with this\n+  _doQuit: false, // Indicates when the service is to be shut down at the end of the request.\n+  _socketClosed: true, // True if the socket in this is closed, false otherwise.","path":"b2g/components/RemoteControlService.jsm","position":60,"original_position":60,"commit_id":"e5f7124be9d2189cd7b24d1176d9114154f198a4","original_commit_id":"e5f7124be9d2189cd7b24d1176d9114154f198a4","user":{"login":"schien","id":1792048,"avatar_url":"https://avatars.githubusercontent.com/u/1792048?v=3","gravatar_id":"","url":"https://api.github.com/users/schien","html_url":"https://github.com/schien","followers_url":"https://api.github.com/users/schien/followers","following_url":"https://api.github.com/users/schien/following{/other_user}","gists_url":"https://api.github.com/users/schien/gists{/gist_id}","starred_url":"https://api.github.com/users/schien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schien/subscriptions","organizations_url":"https://api.github.com/users/schien/orgs","repos_url":"https://api.github.com/users/schien/repos","events_url":"https://api.github.com/users/schien/events{/privacy}","received_events_url":"https://api.github.com/users/schien/received_events","type":"User","site_admin":false},"body":"`_socketClosed` isn't really used in your code, you can simply remove this attribute.","created_at":"2016-05-06T02:50:08Z","updated_at":"2016-05-06T02:50:08Z","html_url":"https://github.com/mozilla-b2g/gecko-b2g/pull/2#discussion_r62283631","pull_request_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/comments/62283631"},"html":{"href":"https://github.com/mozilla-b2g/gecko-b2g/pull/2#discussion_r62283631"},"pull_request":{"href":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/2","id":68971972,"html_url":"https://github.com/mozilla-b2g/gecko-b2g/pull/2","diff_url":"https://github.com/mozilla-b2g/gecko-b2g/pull/2.diff","patch_url":"https://github.com/mozilla-b2g/gecko-b2g/pull/2.patch","issue_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/issues/2","number":2,"state":"open","locked":false,"title":"Bug 1197749 - Add RemoteControlService for remote control feature","user":{"login":"MDTsai","id":5763237,"avatar_url":"https://avatars.githubusercontent.com/u/5763237?v=3","gravatar_id":"","url":"https://api.github.com/users/MDTsai","html_url":"https://github.com/MDTsai","followers_url":"https://api.github.com/users/MDTsai/followers","following_url":"https://api.github.com/users/MDTsai/following{/other_user}","gists_url":"https://api.github.com/users/MDTsai/gists{/gist_id}","starred_url":"https://api.github.com/users/MDTsai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MDTsai/subscriptions","organizations_url":"https://api.github.com/users/MDTsai/orgs","repos_url":"https://api.github.com/users/MDTsai/repos","events_url":"https://api.github.com/users/MDTsai/events{/privacy}","received_events_url":"https://api.github.com/users/MDTsai/received_events","type":"User","site_admin":false},"body":"Add --disable-remote-control-service in b2g/moz.configure for the feature.\r\n\r\nRemoteControlService starts TLS socket server, listen and parse incoming message to event.\r\n\r\nBase on schien comment on 8746461, fix:\r\n1. default turn on service\r\n2. Use random port\r\n3. Use Map for _connections\r\n4. Add broadcast port throught mDNS\r\n5. Use nsIConverterOutputStream and nsIConverterInputStream for getting UTF-8 string from all output and input stream\r\n6. Handle partial string from stream buffer and concatenated string to events","created_at":"2016-05-05T06:47:24Z","updated_at":"2016-05-06T02:50:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"beff3886ea1bcc60d83e1f180e0774d22b2619bb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/2/commits","review_comments_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/2/comments","review_comment_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/issues/2/comments","statuses_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/statuses/e5f7124be9d2189cd7b24d1176d9114154f198a4","head":{"label":"MDTsai:2.6_Bug_1197749","ref":"2.6_Bug_1197749","sha":"e5f7124be9d2189cd7b24d1176d9114154f198a4","user":{"login":"MDTsai","id":5763237,"avatar_url":"https://avatars.githubusercontent.com/u/5763237?v=3","gravatar_id":"","url":"https://api.github.com/users/MDTsai","html_url":"https://github.com/MDTsai","followers_url":"https://api.github.com/users/MDTsai/followers","following_url":"https://api.github.com/users/MDTsai/following{/other_user}","gists_url":"https://api.github.com/users/MDTsai/gists{/gist_id}","starred_url":"https://api.github.com/users/MDTsai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MDTsai/subscriptions","organizations_url":"https://api.github.com/users/MDTsai/orgs","repos_url":"https://api.github.com/users/MDTsai/repos","events_url":"https://api.github.com/users/MDTsai/events{/privacy}","received_events_url":"https://api.github.com/users/MDTsai/received_events","type":"User","site_admin":false},"repo":{"id":43104148,"name":"gecko-dev","full_name":"MDTsai/gecko-dev","owner":{"login":"MDTsai","id":5763237,"avatar_url":"https://avatars.githubusercontent.com/u/5763237?v=3","gravatar_id":"","url":"https://api.github.com/users/MDTsai","html_url":"https://github.com/MDTsai","followers_url":"https://api.github.com/users/MDTsai/followers","following_url":"https://api.github.com/users/MDTsai/following{/other_user}","gists_url":"https://api.github.com/users/MDTsai/gists{/gist_id}","starred_url":"https://api.github.com/users/MDTsai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MDTsai/subscriptions","organizations_url":"https://api.github.com/users/MDTsai/orgs","repos_url":"https://api.github.com/users/MDTsai/repos","events_url":"https://api.github.com/users/MDTsai/events{/privacy}","received_events_url":"https://api.github.com/users/MDTsai/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MDTsai/gecko-dev","description":"Read-only Git mirror of the Mercurial gecko repositories at https://hg.mozilla.org. Please don't submit PRs, see: https://developer.mozilla.org/en-US/docs/Mercurial_FAQ#I%27m_all_used_to_git.2C_but_how_can_I_provide_Mercurial-ready_patches_.3F","fork":true,"url":"https://api.github.com/repos/MDTsai/gecko-dev","forks_url":"https://api.github.com/repos/MDTsai/gecko-dev/forks","keys_url":"https://api.github.com/repos/MDTsai/gecko-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MDTsai/gecko-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MDTsai/gecko-dev/teams","hooks_url":"https://api.github.com/repos/MDTsai/gecko-dev/hooks","issue_events_url":"https://api.github.com/repos/MDTsai/gecko-dev/issues/events{/number}","events_url":"https://api.github.com/repos/MDTsai/gecko-dev/events","assignees_url":"https://api.github.com/repos/MDTsai/gecko-dev/assignees{/user}","branches_url":"https://api.github.com/repos/MDTsai/gecko-dev/branches{/branch}","tags_url":"https://api.github.com/repos/MDTsai/gecko-dev/tags","blobs_url":"https://api.github.com/repos/MDTsai/gecko-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MDTsai/gecko-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MDTsai/gecko-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/MDTsai/gecko-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MDTsai/gecko-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/MDTsai/gecko-dev/languages","stargazers_url":"https://api.github.com/repos/MDTsai/gecko-dev/stargazers","contributors_url":"https://api.github.com/repos/MDTsai/gecko-dev/contributors","subscribers_url":"https://api.github.com/repos/MDTsai/gecko-dev/subscribers","subscription_url":"https://api.github.com/repos/MDTsai/gecko-dev/subscription","commits_url":"https://api.github.com/repos/MDTsai/gecko-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/MDTsai/gecko-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/MDTsai/gecko-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/MDTsai/gecko-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/MDTsai/gecko-dev/contents/{+path}","compare_url":"https://api.github.com/repos/MDTsai/gecko-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MDTsai/gecko-dev/merges","archive_url":"https://api.github.com/repos/MDTsai/gecko-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MDTsai/gecko-dev/downloads","issues_url":"https://api.github.com/repos/MDTsai/gecko-dev/issues{/number}","pulls_url":"https://api.github.com/repos/MDTsai/gecko-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/MDTsai/gecko-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/MDTsai/gecko-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MDTsai/gecko-dev/labels{/name}","releases_url":"https://api.github.com/repos/MDTsai/gecko-dev/releases{/id}","deployments_url":"https://api.github.com/repos/MDTsai/gecko-dev/deployments","created_at":"2015-09-25T02:10:46Z","updated_at":"2015-09-25T02:20:08Z","pushed_at":"2016-05-05T09:02:04Z","git_url":"git://github.com/MDTsai/gecko-dev.git","ssh_url":"git@github.com:MDTsai/gecko-dev.git","clone_url":"https://github.com/MDTsai/gecko-dev.git","svn_url":"https://github.com/MDTsai/gecko-dev","homepage":"https://developer.mozilla.org/docs/Introduction","size":2714301,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"mozilla-b2g:b2g48_v2_6","ref":"b2g48_v2_6","sha":"ccf59a9dda868db58b5d943e2c4235ead89f9344","user":{"login":"mozilla-b2g","id":1261292,"avatar_url":"https://avatars.githubusercontent.com/u/1261292?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-b2g","html_url":"https://github.com/mozilla-b2g","followers_url":"https://api.github.com/users/mozilla-b2g/followers","following_url":"https://api.github.com/users/mozilla-b2g/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-b2g/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-b2g/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-b2g/subscriptions","organizations_url":"https://api.github.com/users/mozilla-b2g/orgs","repos_url":"https://api.github.com/users/mozilla-b2g/repos","events_url":"https://api.github.com/users/mozilla-b2g/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-b2g/received_events","type":"Organization","site_admin":false},"repo":{"id":57910513,"name":"gecko-b2g","full_name":"mozilla-b2g/gecko-b2g","owner":{"login":"mozilla-b2g","id":1261292,"avatar_url":"https://avatars.githubusercontent.com/u/1261292?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla-b2g","html_url":"https://github.com/mozilla-b2g","followers_url":"https://api.github.com/users/mozilla-b2g/followers","following_url":"https://api.github.com/users/mozilla-b2g/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-b2g/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-b2g/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-b2g/subscriptions","organizations_url":"https://api.github.com/users/mozilla-b2g/orgs","repos_url":"https://api.github.com/users/mozilla-b2g/repos","events_url":"https://api.github.com/users/mozilla-b2g/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-b2g/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-b2g/gecko-b2g","description":"For use of TV team - Commits to b2g48_v2_6 done here","fork":true,"url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g","forks_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/forks","keys_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/teams","hooks_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/hooks","issue_events_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/events","assignees_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/tags","blobs_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/languages","stargazers_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/stargazers","contributors_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/contributors","subscribers_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/subscribers","subscription_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/subscription","commits_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/merges","archive_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/downloads","issues_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/deployments","created_at":"2016-05-02T18:14:06Z","updated_at":"2016-05-02T18:19:40Z","pushed_at":"2016-05-05T06:47:24Z","git_url":"git://github.com/mozilla-b2g/gecko-b2g.git","ssh_url":"git@github.com:mozilla-b2g/gecko-b2g.git","clone_url":"https://github.com/mozilla-b2g/gecko-b2g.git","svn_url":"https://github.com/mozilla-b2g/gecko-b2g","homepage":"https://wiki.mozilla.org/TV_2.6","size":2748829,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"b2g48_v2_6"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/2"},"html":{"href":"https://github.com/mozilla-b2g/gecko-b2g/pull/2"},"issue":{"href":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/issues/2"},"comments":{"href":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla-b2g/gecko-b2g/statuses/e5f7124be9d2189cd7b24d1176d9114154f198a4"}}}}