{"action":"created","comment":{"url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/comments/29706144","id":29706144,"diff_hunk":"@@ -0,0 +1,409 @@\n+'use strict';\n+\n+var util = require('util');\n+\n+var Q = require('q');\n+\n+var getOrCreateBridge = require('./helpers/getOrCreateBridge.js');\n+var originator = require('./helpers/originator.js');\n+\n+/**\n+ * Creates a state machine for a shared extension.\n+ * @param {Object} client - the asterisk client instance\n+ * @param {Object} data - the data (trunks, stations, etc.) related to this\n+ *   extension\n+ * @param {Object} channel - the incoming channel\n+ * @return {Object} stateMachine- the state machine related to this extension\n+ */\n+function create(client, data, channel) {\n+  var bridge;\n+  var participants = {};\n+\n+  var stateMachine = {\n+    states: {\n+      BUSY: 'BUSY',\n+      INUSE: 'INUSE',\n+      IDLE: 'NOT_INUSE',\n+      RINGING: 'RINGING',\n+      UNKNOWN: 'UNKNOWN'\n+    },\n+\n+    dialString: '',\n+\n+    allowDtmf: true,\n+\n+    trunkEnteredStasis: false,\n+\n+    /**\n+     * Adds a participant to the participants object.\n+     * @param {Object} participant - the participant channel to be added\n+     */\n+    addParticipant: function(participant) {\n+      participants[participant.id] = participant;\n+\n+      participant.once('StasisStart', this.onParticipantStasisStart);\n+      participant.once('ChannelDestroyed', this.onParticipantHangup);\n+    },\n+    /**\n+     * Figures out if the participants object is empty.\n+     * @return {Boolean} - if participants is empty\n+     */\n+    participantsIsEmpty: function() {\n+      return !Object.keys(participants).length;\n+    },\n+\n+    /**\n+     * Determines if a channel, determined by id, is a station.\n+     * param {String} candidateId - the id of the channel in question\n+     * return {Boolean} - whether or not a channel is a station\n+     */\n+    isStation: function(candidateId) {\n+      console.log('isStation: ' + candidateId);\n+      console.log(participants);\n+\n+      if (candidateId === channel.id) {\n+        return channel.isStation;\n+      } else {\n+        return participants[candidateId].isStation;\n+      }\n+    },\n+\n+    /**\n+     * Cleans up the event listeners of a participant.\n+     * param {Object} participant - the participant channel\n+     */\n+    cleanupParticipantEvents: function(participant) {\n+      participant.removeListener('StasisStart',\n+                                   this.onParticipantStasisStart);\n+      participant.removeListener('ChannelDestroyed',\n+                                 this.onParticipantHangup);\n+    },\n+\n+    /**\n+     * Updates the state (both for ARI and the stateMachine).\n+     * param {String} state - the state to update to\n+     */\n+    updateState: function(state) {\n+      var deviceState = Q.denodeify(\n+        client.deviceStates.update.bind(client)\n+      );\n+\n+      this.currentState = state;\n+\n+      deviceState({\n+        deviceName: util.format('Stasis:%s', data.extension.name),\n+        deviceState: state\n+      });\n+    },\n+\n+    /**\n+     * State machine intializer. Answers incoming channel and determines the\n+     *   device state, and relevant data.\n+     * param {Object} channel - the incoming channel","path":"lib/core/stateMachine.js","position":102,"original_position":102,"commit_id":"3ea8944da959444acc7c7a37b3d05994a4a2e87e","original_commit_id":"3ea8944da959444acc7c7a37b3d05994a4a2e87e","user":{"login":"samuelg","id":21962,"avatar_url":"https://avatars.githubusercontent.com/u/21962?v=3","gravatar_id":"","url":"https://api.github.com/users/samuelg","html_url":"https://github.com/samuelg","followers_url":"https://api.github.com/users/samuelg/followers","following_url":"https://api.github.com/users/samuelg/following{/other_user}","gists_url":"https://api.github.com/users/samuelg/gists{/gist_id}","starred_url":"https://api.github.com/users/samuelg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samuelg/subscriptions","organizations_url":"https://api.github.com/users/samuelg/orgs","repos_url":"https://api.github.com/users/samuelg/repos","events_url":"https://api.github.com/users/samuelg/events{/privacy}","received_events_url":"https://api.github.com/users/samuelg/received_events","type":"User","site_admin":false},"body":"Should read {Channel} channel.","created_at":"2015-05-05T19:55:58Z","updated_at":"2015-05-05T19:55:58Z","html_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances/pull/34#discussion_r29706144","pull_request_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/34","_links":{"self":{"href":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/comments/29706144"},"html":{"href":"https://github.com/wolfeman67/node-ari-shared-line-appearances/pull/34#discussion_r29706144"},"pull_request":{"href":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/34"}}},"pull_request":{"url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/34","id":34760151,"html_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances/pull/34","diff_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances/pull/34.diff","patch_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances/pull/34.patch","issue_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues/34","number":34,"state":"open","locked":false,"title":"Major application refactoring.","user":{"login":"wolfeman67","id":10468003,"avatar_url":"https://avatars.githubusercontent.com/u/10468003?v=3","gravatar_id":"","url":"https://api.github.com/users/wolfeman67","html_url":"https://github.com/wolfeman67","followers_url":"https://api.github.com/users/wolfeman67/followers","following_url":"https://api.github.com/users/wolfeman67/following{/other_user}","gists_url":"https://api.github.com/users/wolfeman67/gists{/gist_id}","starred_url":"https://api.github.com/users/wolfeman67/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wolfeman67/subscriptions","organizations_url":"https://api.github.com/users/wolfeman67/orgs","repos_url":"https://api.github.com/users/wolfeman67/repos","events_url":"https://api.github.com/users/wolfeman67/events{/privacy}","received_events_url":"https://api.github.com/users/wolfeman67/received_events","type":"User","site_admin":false},"body":"Modularized functions, made a state machine which contains application\r\nlogic and event handlers, etc.","created_at":"2015-05-05T19:49:53Z","updated_at":"2015-05-05T19:55:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4dbcbdb5f48c12df58b6d1894f3d2aaa8b8cc3b2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/34/commits","review_comments_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/34/comments","review_comment_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues/34/comments","statuses_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/statuses/3ea8944da959444acc7c7a37b3d05994a4a2e87e","head":{"label":"wolfeman67:refactorSquashed","ref":"refactorSquashed","sha":"3ea8944da959444acc7c7a37b3d05994a4a2e87e","user":{"login":"wolfeman67","id":10468003,"avatar_url":"https://avatars.githubusercontent.com/u/10468003?v=3","gravatar_id":"","url":"https://api.github.com/users/wolfeman67","html_url":"https://github.com/wolfeman67","followers_url":"https://api.github.com/users/wolfeman67/followers","following_url":"https://api.github.com/users/wolfeman67/following{/other_user}","gists_url":"https://api.github.com/users/wolfeman67/gists{/gist_id}","starred_url":"https://api.github.com/users/wolfeman67/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wolfeman67/subscriptions","organizations_url":"https://api.github.com/users/wolfeman67/orgs","repos_url":"https://api.github.com/users/wolfeman67/repos","events_url":"https://api.github.com/users/wolfeman67/events{/privacy}","received_events_url":"https://api.github.com/users/wolfeman67/received_events","type":"User","site_admin":false},"repo":{"id":30209409,"name":"node-ari-shared-line-appearances","full_name":"wolfeman67/node-ari-shared-line-appearances","owner":{"login":"wolfeman67","id":10468003,"avatar_url":"https://avatars.githubusercontent.com/u/10468003?v=3","gravatar_id":"","url":"https://api.github.com/users/wolfeman67","html_url":"https://github.com/wolfeman67","followers_url":"https://api.github.com/users/wolfeman67/followers","following_url":"https://api.github.com/users/wolfeman67/following{/other_user}","gists_url":"https://api.github.com/users/wolfeman67/gists{/gist_id}","starred_url":"https://api.github.com/users/wolfeman67/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wolfeman67/subscriptions","organizations_url":"https://api.github.com/users/wolfeman67/orgs","repos_url":"https://api.github.com/users/wolfeman67/repos","events_url":"https://api.github.com/users/wolfeman67/events{/privacy}","received_events_url":"https://api.github.com/users/wolfeman67/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances","description":"Co-op implementation of SLA in ARI using Node.js","fork":false,"url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances","forks_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/forks","keys_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/teams","hooks_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/hooks","issue_events_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues/events{/number}","events_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/events","assignees_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/assignees{/user}","branches_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/branches{/branch}","tags_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/tags","blobs_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/refs{/sha}","trees_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/statuses/{sha}","languages_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/languages","stargazers_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/stargazers","contributors_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/contributors","subscribers_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/subscribers","subscription_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/subscription","commits_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/commits{/sha}","git_commits_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/commits{/sha}","comments_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/comments{/number}","issue_comment_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues/comments{/number}","contents_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/contents/{+path}","compare_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/merges","archive_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/downloads","issues_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues{/number}","pulls_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls{/number}","milestones_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/milestones{/number}","notifications_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/labels{/name}","releases_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/releases{/id}","created_at":"2015-02-02T21:23:52Z","updated_at":"2015-04-27T20:54:11Z","pushed_at":"2015-05-05T19:49:53Z","git_url":"git://github.com/wolfeman67/node-ari-shared-line-appearances.git","ssh_url":"git@github.com:wolfeman67/node-ari-shared-line-appearances.git","clone_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances.git","svn_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances","homepage":null,"size":1107,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":8,"forks":2,"open_issues":8,"watchers":0,"default_branch":"master"}},"base":{"label":"wolfeman67:master","ref":"master","sha":"22df43ad9d30d5bff0575a2abc2ea6f94ffa56be","user":{"login":"wolfeman67","id":10468003,"avatar_url":"https://avatars.githubusercontent.com/u/10468003?v=3","gravatar_id":"","url":"https://api.github.com/users/wolfeman67","html_url":"https://github.com/wolfeman67","followers_url":"https://api.github.com/users/wolfeman67/followers","following_url":"https://api.github.com/users/wolfeman67/following{/other_user}","gists_url":"https://api.github.com/users/wolfeman67/gists{/gist_id}","starred_url":"https://api.github.com/users/wolfeman67/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wolfeman67/subscriptions","organizations_url":"https://api.github.com/users/wolfeman67/orgs","repos_url":"https://api.github.com/users/wolfeman67/repos","events_url":"https://api.github.com/users/wolfeman67/events{/privacy}","received_events_url":"https://api.github.com/users/wolfeman67/received_events","type":"User","site_admin":false},"repo":{"id":30209409,"name":"node-ari-shared-line-appearances","full_name":"wolfeman67/node-ari-shared-line-appearances","owner":{"login":"wolfeman67","id":10468003,"avatar_url":"https://avatars.githubusercontent.com/u/10468003?v=3","gravatar_id":"","url":"https://api.github.com/users/wolfeman67","html_url":"https://github.com/wolfeman67","followers_url":"https://api.github.com/users/wolfeman67/followers","following_url":"https://api.github.com/users/wolfeman67/following{/other_user}","gists_url":"https://api.github.com/users/wolfeman67/gists{/gist_id}","starred_url":"https://api.github.com/users/wolfeman67/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wolfeman67/subscriptions","organizations_url":"https://api.github.com/users/wolfeman67/orgs","repos_url":"https://api.github.com/users/wolfeman67/repos","events_url":"https://api.github.com/users/wolfeman67/events{/privacy}","received_events_url":"https://api.github.com/users/wolfeman67/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances","description":"Co-op implementation of SLA in ARI using Node.js","fork":false,"url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances","forks_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/forks","keys_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/teams","hooks_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/hooks","issue_events_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues/events{/number}","events_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/events","assignees_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/assignees{/user}","branches_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/branches{/branch}","tags_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/tags","blobs_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/refs{/sha}","trees_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/statuses/{sha}","languages_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/languages","stargazers_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/stargazers","contributors_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/contributors","subscribers_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/subscribers","subscription_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/subscription","commits_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/commits{/sha}","git_commits_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/git/commits{/sha}","comments_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/comments{/number}","issue_comment_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues/comments{/number}","contents_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/contents/{+path}","compare_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/merges","archive_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/downloads","issues_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues{/number}","pulls_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls{/number}","milestones_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/milestones{/number}","notifications_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/labels{/name}","releases_url":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/releases{/id}","created_at":"2015-02-02T21:23:52Z","updated_at":"2015-04-27T20:54:11Z","pushed_at":"2015-05-05T19:49:53Z","git_url":"git://github.com/wolfeman67/node-ari-shared-line-appearances.git","ssh_url":"git@github.com:wolfeman67/node-ari-shared-line-appearances.git","clone_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances.git","svn_url":"https://github.com/wolfeman67/node-ari-shared-line-appearances","homepage":null,"size":1107,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":8,"forks":2,"open_issues":8,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/34"},"html":{"href":"https://github.com/wolfeman67/node-ari-shared-line-appearances/pull/34"},"issue":{"href":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues/34"},"comments":{"href":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/issues/34/comments"},"review_comments":{"href":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/34/comments"},"review_comment":{"href":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/pulls/34/commits"},"statuses":{"href":"https://api.github.com/repos/wolfeman67/node-ari-shared-line-appearances/statuses/3ea8944da959444acc7c7a37b3d05994a4a2e87e"}}}}