{"action":"created","comment":{"url":"https://api.github.com/repos/webrtc/apprtc/pulls/comments/25013995","id":25013995,"diff_hunk":"@@ -9,14 +9,145 @@\n /* More information about these options at jshint.com/docs/options */\n \n // Variables defined in and used from chrome.\n-/* globals chrome */\n+/* globals chrome, sendAsyncUrlRequest, Constants */\n \n 'use strict';\n-chrome.app.runtime.onLaunched.addListener(function() {\n-  chrome.app.window.create('appwindow.html', {\n-    'width': 800,\n-    'height': 600,\n-    'left': 0,\n-    'top': 0\n+(function() {\n+  chrome.app.runtime.onLaunched.addListener(function() {\n+    chrome.app.window.create('appwindow.html', {\n+      'width': 800,\n+      'height': 600,\n+      'left': 0,\n+      'top': 0\n+    });\n   });\n-});\n+\n+  // Send message from background to window.\n+  var sendMessageToWindow = function(port, message) {\n+    trace('B -> W: ' + JSON.stringify(message));\n+    try {\n+      port.postMessage(message);\n+    }\n+    catch (ex) {\n+      trace('Error sending message: ' + ex);\n+    }\n+  };\n+\n+  var handleWebSocketRequest = function(port, message) {\n+    if (message.wsAction === Constants.CREATE_ACTION) {\n+      trace('RWS: creating web socket: ' + message.wssUrl);\n+      var ws = new WebSocket(message.wssUrl);\n+      ws.onopen = function() {\n+        trace('RWS: onopen');\n+        sendMessageToWindow(port, {\n+          action: Constants.WS_ACTION,\n+          wsAction: Constants.ACTION_EVENT,\n+          wsEvent: Constants.EVENT_ONOPEN\n+        });\n+      };\n+      ws.onerror = function() {\n+        trace('RWS: onerror.');\n+        sendMessageToWindow(port, {\n+          action: Constants.WS_ACTION,\n+          wsAction: Constants.ACTION_EVENT,\n+          wsEvent: Constants.EVENT_ONERROR\n+        });\n+      };\n+      ws.onclose = function(event) {\n+        trace('RWS: onclose - code: ' + event.code + ' reason: ' +\n+            event.reason);\n+        sendMessageToWindow(port, {\n+          action: Constants.WS_ACTION,\n+          wsAction: Constants.ACTION_EVENT,\n+          wsEvent: Constants.EVENT_ONCLOSE,\n+          data: event\n+        });\n+      };\n+      ws.onmessage = function(event) {\n+        trace('RWS: onmessage: ' + event.data);\n+        sendMessageToWindow(port, {\n+          action: Constants.WS_ACTION,\n+          wsAction: Constants.ACTION_EVENT,\n+          wsEvent: Constants.EVENT_ONMESSAGE,\n+          data: event\n+        });\n+      };\n+      port.webSocket_ = ws;","path":"src/web_app/js/background.js","position":75,"original_position":75,"commit_id":"2733ecd1e50112ea8215764684af8387fcc760de","original_commit_id":"2733ecd1e50112ea8215764684af8387fcc760de","user":{"login":"jiayliu","id":7770539,"avatar_url":"https://avatars.githubusercontent.com/u/7770539?v=3","gravatar_id":"","url":"https://api.github.com/users/jiayliu","html_url":"https://github.com/jiayliu","followers_url":"https://api.github.com/users/jiayliu/followers","following_url":"https://api.github.com/users/jiayliu/following{/other_user}","gists_url":"https://api.github.com/users/jiayliu/gists{/gist_id}","starred_url":"https://api.github.com/users/jiayliu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jiayliu/subscriptions","organizations_url":"https://api.github.com/users/jiayliu/orgs","repos_url":"https://api.github.com/users/jiayliu/repos","events_url":"https://api.github.com/users/jiayliu/events{/privacy}","received_events_url":"https://api.github.com/users/jiayliu/received_events","type":"User","site_admin":false},"body":"Encapsulate webSocket_ in Port and provide access methods? ","created_at":"2015-02-19T18:57:03Z","updated_at":"2015-02-19T18:57:03Z","html_url":"https://github.com/webrtc/apprtc/pull/82#discussion_r25013995","pull_request_url":"https://api.github.com/repos/webrtc/apprtc/pulls/82","_links":{"self":{"href":"https://api.github.com/repos/webrtc/apprtc/pulls/comments/25013995"},"html":{"href":"https://github.com/webrtc/apprtc/pull/82#discussion_r25013995"},"pull_request":{"href":"https://api.github.com/repos/webrtc/apprtc/pulls/82"}}},"pull_request":{"url":"https://api.github.com/repos/webrtc/apprtc/pulls/82","id":29574140,"html_url":"https://github.com/webrtc/apprtc/pull/82","diff_url":"https://github.com/webrtc/apprtc/pull/82.diff","patch_url":"https://github.com/webrtc/apprtc/pull/82.patch","issue_url":"https://api.github.com/repos/webrtc/apprtc/issues/82","number":82,"state":"open","locked":false,"title":"Set up Chrome App shutdown flow.","user":{"login":"chuckhays","id":1405600,"avatar_url":"https://avatars.githubusercontent.com/u/1405600?v=3","gravatar_id":"","url":"https://api.github.com/users/chuckhays","html_url":"https://github.com/chuckhays","followers_url":"https://api.github.com/users/chuckhays/followers","following_url":"https://api.github.com/users/chuckhays/following{/other_user}","gists_url":"https://api.github.com/users/chuckhays/gists{/gist_id}","starred_url":"https://api.github.com/users/chuckhays/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chuckhays/subscriptions","organizations_url":"https://api.github.com/users/chuckhays/orgs","repos_url":"https://api.github.com/users/chuckhays/repos","events_url":"https://api.github.com/users/chuckhays/events{/privacy}","received_events_url":"https://api.github.com/users/chuckhays/received_events","type":"User","site_admin":false},"body":"Makes the following changes:\r\n* Support both sync/async hangup flow. Sync is used when web browser closes so all cleanup calls can finish before browser closes, async is used when hang up button is pressed. Chrome App can't do sync xhr, so hang up flow has to be async.\r\n* Moves websocket ownership to background.js in the Chrome App\r\n* Adds a queue of cleanup actions in background.js that are executed when the Chrome App window closes\r\n\r\nOnly background.js knows when the app window closes, and once it has already closed, the window can no longer do xhr or web socket requests. Therefore, background.js has to take care of the clean up calls required to end the in progress call. \r\n\r\n@tkchin @jiayliu \r\n\r\nI'm still working to see if I can unit test more of the code, but wanted to send this out to get the review started, as it is a pretty complex bit of code.","created_at":"2015-02-18T23:28:01Z","updated_at":"2015-02-19T18:57:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a78fc62392c38c379533f707af6e2c8b2e91b9ff","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/webrtc/apprtc/pulls/82/commits","review_comments_url":"https://api.github.com/repos/webrtc/apprtc/pulls/82/comments","review_comment_url":"https://api.github.com/repos/webrtc/apprtc/pulls/comments/{number}","comments_url":"https://api.github.com/repos/webrtc/apprtc/issues/82/comments","statuses_url":"https://api.github.com/repos/webrtc/apprtc/statuses/2733ecd1e50112ea8215764684af8387fcc760de","head":{"label":"chuckhays:leave","ref":"leave","sha":"2733ecd1e50112ea8215764684af8387fcc760de","user":{"login":"chuckhays","id":1405600,"avatar_url":"https://avatars.githubusercontent.com/u/1405600?v=3","gravatar_id":"","url":"https://api.github.com/users/chuckhays","html_url":"https://github.com/chuckhays","followers_url":"https://api.github.com/users/chuckhays/followers","following_url":"https://api.github.com/users/chuckhays/following{/other_user}","gists_url":"https://api.github.com/users/chuckhays/gists{/gist_id}","starred_url":"https://api.github.com/users/chuckhays/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chuckhays/subscriptions","organizations_url":"https://api.github.com/users/chuckhays/orgs","repos_url":"https://api.github.com/users/chuckhays/repos","events_url":"https://api.github.com/users/chuckhays/events{/privacy}","received_events_url":"https://api.github.com/users/chuckhays/received_events","type":"User","site_admin":false},"repo":{"id":30306707,"name":"apprtc","full_name":"chuckhays/apprtc","owner":{"login":"chuckhays","id":1405600,"avatar_url":"https://avatars.githubusercontent.com/u/1405600?v=3","gravatar_id":"","url":"https://api.github.com/users/chuckhays","html_url":"https://github.com/chuckhays","followers_url":"https://api.github.com/users/chuckhays/followers","following_url":"https://api.github.com/users/chuckhays/following{/other_user}","gists_url":"https://api.github.com/users/chuckhays/gists{/gist_id}","starred_url":"https://api.github.com/users/chuckhays/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chuckhays/subscriptions","organizations_url":"https://api.github.com/users/chuckhays/orgs","repos_url":"https://api.github.com/users/chuckhays/repos","events_url":"https://api.github.com/users/chuckhays/events{/privacy}","received_events_url":"https://api.github.com/users/chuckhays/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chuckhays/apprtc","description":"The video chat demo app based on WebRTC","fork":true,"url":"https://api.github.com/repos/chuckhays/apprtc","forks_url":"https://api.github.com/repos/chuckhays/apprtc/forks","keys_url":"https://api.github.com/repos/chuckhays/apprtc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chuckhays/apprtc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chuckhays/apprtc/teams","hooks_url":"https://api.github.com/repos/chuckhays/apprtc/hooks","issue_events_url":"https://api.github.com/repos/chuckhays/apprtc/issues/events{/number}","events_url":"https://api.github.com/repos/chuckhays/apprtc/events","assignees_url":"https://api.github.com/repos/chuckhays/apprtc/assignees{/user}","branches_url":"https://api.github.com/repos/chuckhays/apprtc/branches{/branch}","tags_url":"https://api.github.com/repos/chuckhays/apprtc/tags","blobs_url":"https://api.github.com/repos/chuckhays/apprtc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chuckhays/apprtc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chuckhays/apprtc/git/refs{/sha}","trees_url":"https://api.github.com/repos/chuckhays/apprtc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chuckhays/apprtc/statuses/{sha}","languages_url":"https://api.github.com/repos/chuckhays/apprtc/languages","stargazers_url":"https://api.github.com/repos/chuckhays/apprtc/stargazers","contributors_url":"https://api.github.com/repos/chuckhays/apprtc/contributors","subscribers_url":"https://api.github.com/repos/chuckhays/apprtc/subscribers","subscription_url":"https://api.github.com/repos/chuckhays/apprtc/subscription","commits_url":"https://api.github.com/repos/chuckhays/apprtc/commits{/sha}","git_commits_url":"https://api.github.com/repos/chuckhays/apprtc/git/commits{/sha}","comments_url":"https://api.github.com/repos/chuckhays/apprtc/comments{/number}","issue_comment_url":"https://api.github.com/repos/chuckhays/apprtc/issues/comments/{number}","contents_url":"https://api.github.com/repos/chuckhays/apprtc/contents/{+path}","compare_url":"https://api.github.com/repos/chuckhays/apprtc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chuckhays/apprtc/merges","archive_url":"https://api.github.com/repos/chuckhays/apprtc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chuckhays/apprtc/downloads","issues_url":"https://api.github.com/repos/chuckhays/apprtc/issues{/number}","pulls_url":"https://api.github.com/repos/chuckhays/apprtc/pulls{/number}","milestones_url":"https://api.github.com/repos/chuckhays/apprtc/milestones{/number}","notifications_url":"https://api.github.com/repos/chuckhays/apprtc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chuckhays/apprtc/labels{/name}","releases_url":"https://api.github.com/repos/chuckhays/apprtc/releases{/id}","created_at":"2015-02-04T15:50:09Z","updated_at":"2015-02-18T23:04:43Z","pushed_at":"2015-02-18T23:23:59Z","git_url":"git://github.com/chuckhays/apprtc.git","ssh_url":"git@github.com:chuckhays/apprtc.git","clone_url":"https://github.com/chuckhays/apprtc.git","svn_url":"https://github.com/chuckhays/apprtc","homepage":null,"size":3301,"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":"webrtc:master","ref":"master","sha":"9af91ecea2cfeefbccf549892f5307a189573e53","user":{"login":"webrtc","id":10526312,"avatar_url":"https://avatars.githubusercontent.com/u/10526312?v=3","gravatar_id":"","url":"https://api.github.com/users/webrtc","html_url":"https://github.com/webrtc","followers_url":"https://api.github.com/users/webrtc/followers","following_url":"https://api.github.com/users/webrtc/following{/other_user}","gists_url":"https://api.github.com/users/webrtc/gists{/gist_id}","starred_url":"https://api.github.com/users/webrtc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webrtc/subscriptions","organizations_url":"https://api.github.com/users/webrtc/orgs","repos_url":"https://api.github.com/users/webrtc/repos","events_url":"https://api.github.com/users/webrtc/events{/privacy}","received_events_url":"https://api.github.com/users/webrtc/received_events","type":"Organization","site_admin":false},"repo":{"id":30257092,"name":"apprtc","full_name":"webrtc/apprtc","owner":{"login":"webrtc","id":10526312,"avatar_url":"https://avatars.githubusercontent.com/u/10526312?v=3","gravatar_id":"","url":"https://api.github.com/users/webrtc","html_url":"https://github.com/webrtc","followers_url":"https://api.github.com/users/webrtc/followers","following_url":"https://api.github.com/users/webrtc/following{/other_user}","gists_url":"https://api.github.com/users/webrtc/gists{/gist_id}","starred_url":"https://api.github.com/users/webrtc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webrtc/subscriptions","organizations_url":"https://api.github.com/users/webrtc/orgs","repos_url":"https://api.github.com/users/webrtc/repos","events_url":"https://api.github.com/users/webrtc/events{/privacy}","received_events_url":"https://api.github.com/users/webrtc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/webrtc/apprtc","description":"The video chat demo app based on WebRTC","fork":false,"url":"https://api.github.com/repos/webrtc/apprtc","forks_url":"https://api.github.com/repos/webrtc/apprtc/forks","keys_url":"https://api.github.com/repos/webrtc/apprtc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/webrtc/apprtc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/webrtc/apprtc/teams","hooks_url":"https://api.github.com/repos/webrtc/apprtc/hooks","issue_events_url":"https://api.github.com/repos/webrtc/apprtc/issues/events{/number}","events_url":"https://api.github.com/repos/webrtc/apprtc/events","assignees_url":"https://api.github.com/repos/webrtc/apprtc/assignees{/user}","branches_url":"https://api.github.com/repos/webrtc/apprtc/branches{/branch}","tags_url":"https://api.github.com/repos/webrtc/apprtc/tags","blobs_url":"https://api.github.com/repos/webrtc/apprtc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/webrtc/apprtc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/webrtc/apprtc/git/refs{/sha}","trees_url":"https://api.github.com/repos/webrtc/apprtc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/webrtc/apprtc/statuses/{sha}","languages_url":"https://api.github.com/repos/webrtc/apprtc/languages","stargazers_url":"https://api.github.com/repos/webrtc/apprtc/stargazers","contributors_url":"https://api.github.com/repos/webrtc/apprtc/contributors","subscribers_url":"https://api.github.com/repos/webrtc/apprtc/subscribers","subscription_url":"https://api.github.com/repos/webrtc/apprtc/subscription","commits_url":"https://api.github.com/repos/webrtc/apprtc/commits{/sha}","git_commits_url":"https://api.github.com/repos/webrtc/apprtc/git/commits{/sha}","comments_url":"https://api.github.com/repos/webrtc/apprtc/comments{/number}","issue_comment_url":"https://api.github.com/repos/webrtc/apprtc/issues/comments/{number}","contents_url":"https://api.github.com/repos/webrtc/apprtc/contents/{+path}","compare_url":"https://api.github.com/repos/webrtc/apprtc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/webrtc/apprtc/merges","archive_url":"https://api.github.com/repos/webrtc/apprtc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/webrtc/apprtc/downloads","issues_url":"https://api.github.com/repos/webrtc/apprtc/issues{/number}","pulls_url":"https://api.github.com/repos/webrtc/apprtc/pulls{/number}","milestones_url":"https://api.github.com/repos/webrtc/apprtc/milestones{/number}","notifications_url":"https://api.github.com/repos/webrtc/apprtc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/webrtc/apprtc/labels{/name}","releases_url":"https://api.github.com/repos/webrtc/apprtc/releases{/id}","created_at":"2015-02-03T18:10:41Z","updated_at":"2015-02-19T08:30:32Z","pushed_at":"2015-02-19T08:30:31Z","git_url":"git://github.com/webrtc/apprtc.git","ssh_url":"git@github.com:webrtc/apprtc.git","clone_url":"https://github.com/webrtc/apprtc.git","svn_url":"https://github.com/webrtc/apprtc","homepage":"https://apprtc.webrtc.org","size":4506,"stargazers_count":23,"watchers_count":23,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":32,"forks":13,"open_issues":32,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/webrtc/apprtc/pulls/82"},"html":{"href":"https://github.com/webrtc/apprtc/pull/82"},"issue":{"href":"https://api.github.com/repos/webrtc/apprtc/issues/82"},"comments":{"href":"https://api.github.com/repos/webrtc/apprtc/issues/82/comments"},"review_comments":{"href":"https://api.github.com/repos/webrtc/apprtc/pulls/82/comments"},"review_comment":{"href":"https://api.github.com/repos/webrtc/apprtc/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/webrtc/apprtc/pulls/82/commits"},"statuses":{"href":"https://api.github.com/repos/webrtc/apprtc/statuses/2733ecd1e50112ea8215764684af8387fcc760de"}}}}