GitHub PullRequestReviewCommentEvent at 2014-06-26 09:28:23
Repository: loop-server
Actor: ametaireau
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/mozilla-services/loop-server/pulls/comments/14231952","id":14231952,"diff_hunk":"@@ -0,0 +1,460 @@\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\n+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n+\n+\"use strict\";\n+\n+var WebSocket = require('ws');\n+var PubSub = require('./pubsub');\n+\n+\n+function serverError(error, callback) {\n+  if (error) {\n+    error.isCritical = true;\n+    if (callback) callback(error);\n+    return true;\n+  }\n+  return false;\n+}\n+\n+function MessageHandler(pub, sub, storage, tokenManager, conf) {\n+  this.pub = pub;\n+  this.sub = sub;\n+  this.storage = storage;\n+  this.tokenManager = tokenManager;\n+  this.conf = conf;\n+}\n+\n+MessageHandler.prototype = {\n+\n+  /**\n+   * Parses a message and dispatches it to the right handler.\n+   **/\n+  dispatch: function(session, data, callback) {\n+    var inboundMessage;\n+    try {\n+      inboundMessage = this.decode(data);\n+    } catch (e) {\n+      callback(new Error(\"Malformed message.\"));\n+      return;\n+    }\n+\n+    var handlers = {\n+      hello: \"handleHello\",\n+      action: \"handleAction\"\n+    };\n+\n+    var messageType = inboundMessage.messageType;\n+\n+    if (!handlers.hasOwnProperty(messageType)) {\n+      callback(new Error(\"Unknown messageType\"));\n+      return;\n+    }\n+    var handler = this[handlers[messageType]].bind(this);\n+    handler(session, inboundMessage, function(err, outboundMessage, terminate) {\n+      callback(err, this.encode(outboundMessage), terminate);\n+    }.bind(this));\n+  },\n+\n+  /**\n+   * Handles the hello message.\n+   *\n+   * Does authentication (checks that the passed hawk credentials are valid,\n+   * and answers with the status of the call.\n+   *\n+   * In addition to that, listens on the pubsub for forward events about this\n+   * call.\n+   **/\n+  handleHello: function(session, message, callback) {\n+    // Check that message contains requireParams, otherwise return an error.\n+    try {\n+      this.requireParams(message, 'callId', 'authType', 'auth');\n+    } catch (e) {\n+      callback(e);\n+      return;\n+    }\n+\n+\n+    // Configure the current session with user information.\n+    session.callId = message.callId;\n+\n+    var self = this;\n+    var authType = message.authType.toLowerCase();\n+    var tokenId = message.auth;\n+\n+\n+    function processCall(call) {\n+      session.type = (call.userMac === session.user) ? \"callee\" : \"caller\";\n+\n+      // Get current call state to answer hello message.\n+      self.storage.getCallState(session.callId, function(err, currentState) {\n+        if (serverError(err, callback)) return;\n+\n+        // Alert clients on call state changes.\n+        self.sub.on(\"message\", function listener(channel, data) {\n+          var parts = data.split(\":\");\n+          var receivedState = parts[0];\n+          var reason = parts[1];\n+\n+          var terminate;\n+          if (channel === session.callId) {\n+            if (receivedState === \"terminated\" ||\n+                receivedState === \"connected\") {\n+              terminate = \"closeConnection\";\n+              self.sub.removeListener(\"message\", listener);\n+            }\n+            var message = {\n+              messageType: \"progress\",\n+              state: receivedState\n+            };\n+            if (reason !== undefined) {\n+              message.reason = reason;\n+            }\n+\n+            callback(null, message, terminate);\n+          }\n+        });\n+\n+        self.storage.getCallStateTTL(session.callId, function(err, timeoutTTL) {\n+          if (serverError(err, callback)) return;\n+          setTimeout(function() {\n+            self.storage.getCallStateTTL(session.callId, function(err, ttl) {\n+              if (ttl === -1) {\n+                self.broadcastState(session.callId, \"terminated:timeout\");\n+              }\n+            });\n+          }, timeoutTTL * 1000);\n+\n+          // Subscribe to the channel to setup progress updates.\n+          self.sub.subscribe(session.callId);\n+\n+          var helloState = currentState;\n+          if (currentState === \"half-initiated\") {","path":"loop/websockets.js","position":132,"original_position":132,"commit_id":"57ff20c7abed53574e6c747915ee58c710dcee89","original_commit_id":"57ff20c7abed53574e6c747915ee58c710dcee89","user":{"login":"ametaireau","id":67073,"avatar_url":"https://avatars.githubusercontent.com/u/67073?","gravatar_id":"1b3ec4d4db1722e0459151ff9fd054f2","url":"https://api.github.com/users/ametaireau","html_url":"https://github.com/ametaireau","followers_url":"https://api.github.com/users/ametaireau/followers","following_url":"https://api.github.com/users/ametaireau/following{/other_user}","gists_url":"https://api.github.com/users/ametaireau/gists{/gist_id}","starred_url":"https://api.github.com/users/ametaireau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ametaireau/subscriptions","organizations_url":"https://api.github.com/users/ametaireau/orgs","repos_url":"https://api.github.com/users/ametaireau/repos","events_url":"https://api.github.com/users/ametaireau/events{/privacy}","received_events_url":"https://api.github.com/users/ametaireau/received_events","type":"User","site_admin":false},"body":"comment: add the fact that this is implementation detail we want to keep clear of the client.","created_at":"2014-06-26T09:28:23Z","updated_at":"2014-06-26T09:28:23Z","html_url":"https://github.com/mozilla-services/loop-server/pull/115#discussion_r14231952","pull_request_url":"https://api.github.com/repos/mozilla-services/loop-server/pulls/115","_links":{"self":{"href":"https://api.github.com/repos/mozilla-services/loop-server/pulls/comments/14231952"},"html":{"href":"https://github.com/mozilla-services/loop-server/pull/115#discussion_r14231952"},"pull_request":{"href":"https://api.github.com/repos/mozilla-services/loop-server/pulls/115"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla-services/loop-server/pulls/115","id":17410779,"html_url":"https://github.com/mozilla-services/loop-server/pull/115","diff_url":"https://github.com/mozilla-services/loop-server/pull/115.diff","patch_url":"https://github.com/mozilla-services/loop-server/pull/115.patch","issue_url":"https://api.github.com/repos/mozilla-services/loop-server/issues/115","number":115,"state":"open","title":"Bug 1025872 — Setup websockets for call setup information","user":{"login":"Natim","id":229453,"avatar_url":"https://avatars.githubusercontent.com/u/229453?","gravatar_id":"48e87ebebf7bee2a0ca10aa2362795a6","url":"https://api.github.com/users/Natim","html_url":"https://github.com/Natim","followers_url":"https://api.github.com/users/Natim/followers","following_url":"https://api.github.com/users/Natim/following{/other_user}","gists_url":"https://api.github.com/users/Natim/gists{/gist_id}","starred_url":"https://api.github.com/users/Natim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Natim/subscriptions","organizations_url":"https://api.github.com/users/Natim/orgs","repos_url":"https://api.github.com/users/Natim/repos","events_url":"https://api.github.com/users/Natim/events{/privacy}","received_events_url":"https://api.github.com/users/Natim/received_events","type":"User","site_admin":false},"body":"The API has been defined by @adamroach in this document: https://wiki.mozilla.org/Loop/Architecture/MVP#WebSockets_Connection_for_Call_Progress","created_at":"2014-06-20T15:15:53Z","updated_at":"2014-06-26T09:28:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de6de189de7f2c2618c8bef7f1a3d85dbca6b87b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla-services/loop-server/pulls/115/commits","review_comments_url":"https://api.github.com/repos/mozilla-services/loop-server/pulls/115/comments","review_comment_url":"https://api.github.com/repos/mozilla-services/loop-server/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mozilla-services/loop-server/issues/115/comments","statuses_url":"https://api.github.com/repos/mozilla-services/loop-server/statuses/57ff20c7abed53574e6c747915ee58c710dcee89","head":{"label":"mozilla-services:bug1025872/websockets","ref":"bug1025872/websockets","sha":"57ff20c7abed53574e6c747915ee58c710dcee89","user":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?","gravatar_id":"a41a81f9188770933a4b54382c29cae4","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"repo":{"id":17026140,"name":"loop-server","full_name":"mozilla-services/loop-server","owner":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?","gravatar_id":"a41a81f9188770933a4b54382c29cae4","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-services/loop-server","description":"The mozilla loop server","fork":false,"url":"https://api.github.com/repos/mozilla-services/loop-server","forks_url":"https://api.github.com/repos/mozilla-services/loop-server/forks","keys_url":"https://api.github.com/repos/mozilla-services/loop-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-services/loop-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-services/loop-server/teams","hooks_url":"https://api.github.com/repos/mozilla-services/loop-server/hooks","issue_events_url":"https://api.github.com/repos/mozilla-services/loop-server/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-services/loop-server/events","assignees_url":"https://api.github.com/repos/mozilla-services/loop-server/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-services/loop-server/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-services/loop-server/tags","blobs_url":"https://api.github.com/repos/mozilla-services/loop-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-services/loop-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-services/loop-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-services/loop-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-services/loop-server/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-services/loop-server/languages","stargazers_url":"https://api.github.com/repos/mozilla-services/loop-server/stargazers","contributors_url":"https://api.github.com/repos/mozilla-services/loop-server/contributors","subscribers_url":"https://api.github.com/repos/mozilla-services/loop-server/subscribers","subscription_url":"https://api.github.com/repos/mozilla-services/loop-server/subscription","commits_url":"https://api.github.com/repos/mozilla-services/loop-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-services/loop-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-services/loop-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-services/loop-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla-services/loop-server/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-services/loop-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-services/loop-server/merges","archive_url":"https://api.github.com/repos/mozilla-services/loop-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-services/loop-server/downloads","issues_url":"https://api.github.com/repos/mozilla-services/loop-server/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-services/loop-server/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-services/loop-server/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-services/loop-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-services/loop-server/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-services/loop-server/releases{/id}","created_at":"2014-02-20T16:02:00Z","updated_at":"2014-06-25T14:46:52Z","pushed_at":"2014-06-25T16:57:40Z","git_url":"git://github.com/mozilla-services/loop-server.git","ssh_url":"git@github.com:mozilla-services/loop-server.git","clone_url":"https://github.com/mozilla-services/loop-server.git","svn_url":"https://github.com/mozilla-services/loop-server","homepage":null,"size":6549,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":4,"mirror_url":null,"open_issues_count":6,"forks":4,"open_issues":6,"watchers":3,"default_branch":"master"}},"base":{"label":"mozilla-services:master","ref":"master","sha":"7eeb3c605f36eb42bc30f6d78de82a1fa4939ba0","user":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?","gravatar_id":"a41a81f9188770933a4b54382c29cae4","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"repo":{"id":17026140,"name":"loop-server","full_name":"mozilla-services/loop-server","owner":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?","gravatar_id":"a41a81f9188770933a4b54382c29cae4","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-services/loop-server","description":"The mozilla loop server","fork":false,"url":"https://api.github.com/repos/mozilla-services/loop-server","forks_url":"https://api.github.com/repos/mozilla-services/loop-server/forks","keys_url":"https://api.github.com/repos/mozilla-services/loop-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-services/loop-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-services/loop-server/teams","hooks_url":"https://api.github.com/repos/mozilla-services/loop-server/hooks","issue_events_url":"https://api.github.com/repos/mozilla-services/loop-server/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-services/loop-server/events","assignees_url":"https://api.github.com/repos/mozilla-services/loop-server/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-services/loop-server/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-services/loop-server/tags","blobs_url":"https://api.github.com/repos/mozilla-services/loop-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-services/loop-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-services/loop-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-services/loop-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-services/loop-server/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-services/loop-server/languages","stargazers_url":"https://api.github.com/repos/mozilla-services/loop-server/stargazers","contributors_url":"https://api.github.com/repos/mozilla-services/loop-server/contributors","subscribers_url":"https://api.github.com/repos/mozilla-services/loop-server/subscribers","subscription_url":"https://api.github.com/repos/mozilla-services/loop-server/subscription","commits_url":"https://api.github.com/repos/mozilla-services/loop-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-services/loop-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-services/loop-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-services/loop-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla-services/loop-server/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-services/loop-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-services/loop-server/merges","archive_url":"https://api.github.com/repos/mozilla-services/loop-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-services/loop-server/downloads","issues_url":"https://api.github.com/repos/mozilla-services/loop-server/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-services/loop-server/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-services/loop-server/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-services/loop-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-services/loop-server/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-services/loop-server/releases{/id}","created_at":"2014-02-20T16:02:00Z","updated_at":"2014-06-25T14:46:52Z","pushed_at":"2014-06-25T16:57:40Z","git_url":"git://github.com/mozilla-services/loop-server.git","ssh_url":"git@github.com:mozilla-services/loop-server.git","clone_url":"https://github.com/mozilla-services/loop-server.git","svn_url":"https://github.com/mozilla-services/loop-server","homepage":null,"size":6549,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":4,"mirror_url":null,"open_issues_count":6,"forks":4,"open_issues":6,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla-services/loop-server/pulls/115"},"html":{"href":"https://github.com/mozilla-services/loop-server/pull/115"},"issue":{"href":"https://api.github.com/repos/mozilla-services/loop-server/issues/115"},"comments":{"href":"https://api.github.com/repos/mozilla-services/loop-server/issues/115/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla-services/loop-server/pulls/115/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla-services/loop-server/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mozilla-services/loop-server/pulls/115/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla-services/loop-server/statuses/57ff20c7abed53574e6c747915ee58c710dcee89"}}}}