{"action":"created","comment":{"url":"https://api.github.com/repos/pusher/pusher-js/pulls/comments/41097008","id":41097008,"diff_hunk":"@@ -13,6 +13,8 @@\n   }\n   var prototype = ScriptRequest.prototype;\n \n+  var _document = Pusher.runtime.getDocument();","path":"src/dom/script_request.js","position":4,"original_position":4,"commit_id":"e5ad496a975e9fbf401bae2f31471934b3e50f25","original_commit_id":"e5ad496a975e9fbf401bae2f31471934b3e50f25","user":{"login":"leggetter","id":328367,"avatar_url":"https://avatars.githubusercontent.com/u/328367?v=3","gravatar_id":"","url":"https://api.github.com/users/leggetter","html_url":"https://github.com/leggetter","followers_url":"https://api.github.com/users/leggetter/followers","following_url":"https://api.github.com/users/leggetter/following{/other_user}","gists_url":"https://api.github.com/users/leggetter/gists{/gist_id}","starred_url":"https://api.github.com/users/leggetter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leggetter/subscriptions","organizations_url":"https://api.github.com/users/leggetter/orgs","repos_url":"https://api.github.com/users/leggetter/repos","events_url":"https://api.github.com/users/leggetter/events{/privacy}","received_events_url":"https://api.github.com/users/leggetter/received_events","type":"User","site_admin":false},"body":"Doing a request for a file via dynamically creating a `script` tag feels browser runtime specific. So maybe this would be moved into `Pusher.Runtime` if we proceed?","created_at":"2015-10-04T11:47:25Z","updated_at":"2015-10-04T11:47:25Z","html_url":"https://github.com/pusher/pusher-js/pull/128#discussion_r41097008","pull_request_url":"https://api.github.com/repos/pusher/pusher-js/pulls/128","_links":{"self":{"href":"https://api.github.com/repos/pusher/pusher-js/pulls/comments/41097008"},"html":{"href":"https://github.com/pusher/pusher-js/pull/128#discussion_r41097008"},"pull_request":{"href":"https://api.github.com/repos/pusher/pusher-js/pulls/128"}}},"pull_request":{"url":"https://api.github.com/repos/pusher/pusher-js/pulls/128","id":46723572,"html_url":"https://github.com/pusher/pusher-js/pull/128","diff_url":"https://github.com/pusher/pusher-js/pull/128.diff","patch_url":"https://github.com/pusher/pusher-js/pull/128.patch","issue_url":"https://api.github.com/repos/pusher/pusher-js/issues/128","number":128,"state":"open","locked":false,"title":"[[Speculative]] Abstract `window` and `document` behind a `Pusher.runtime` object","user":{"login":"jpatel531","id":7556206,"avatar_url":"https://avatars.githubusercontent.com/u/7556206?v=3","gravatar_id":"","url":"https://api.github.com/users/jpatel531","html_url":"https://github.com/jpatel531","followers_url":"https://api.github.com/users/jpatel531/followers","following_url":"https://api.github.com/users/jpatel531/following{/other_user}","gists_url":"https://api.github.com/users/jpatel531/gists{/gist_id}","starred_url":"https://api.github.com/users/jpatel531/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpatel531/subscriptions","organizations_url":"https://api.github.com/users/jpatel531/orgs","repos_url":"https://api.github.com/users/jpatel531/repos","events_url":"https://api.github.com/users/jpatel531/events{/privacy}","received_events_url":"https://api.github.com/users/jpatel531/received_events","type":"User","site_admin":false},"body":"Still untidy and a work in progress and is meant to be a piece for discussion rather than anything else. It came about when I tried to get PusherJS working for ReactNative, but the ReactNative runtime does not have a `document`. @leggetter recommended I try to get PusherJS working in a WebWorker to test things out. WebWorkers, similarly, do not have a `document`, nor does it have a `window`.\r\n\r\nThis basically detects the runtime environment, i.e. `Browser` or `NonBrowser`. Each `runtime` has `getWindow` and `getDocument` method. I've replaced all direct references to `window` and `document` to `Pusher.runtime.getWindow()` and `Pusher.runtime.getDocument()` respectively. As a result, the library can supply an appropriate value for `window` and `document` based on the environment.\r\n\r\nAt the moment this is _very_ hacky. There's no appropriate \"mock\" for `getDocument ` in a non-browser environment - still trying to think about that. PusherJS works in a WebWorker with these changes, and the following code:\r\n\r\n```js\r\nimportScripts(\"pusher.js\");\r\n\r\nvar pusher = new Pusher('app_key', {\r\n  disableStats: true\r\n});\r\n\r\nvar channel = pusher.subscribe('test_channel');\r\n\r\nchannel.bind('my_event', function(data) {\r\n  postMessage(data); // send the data to the application thread\r\n});\r\n```\r\n\r\nWDYT @pl @leggetter @zimbatm ? Is it at least the right start?","created_at":"2015-10-04T11:25:50Z","updated_at":"2015-10-04T11:47:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7055d1f1c72571dc2615ccf501cdf73c1d514011","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pusher/pusher-js/pulls/128/commits","review_comments_url":"https://api.github.com/repos/pusher/pusher-js/pulls/128/comments","review_comment_url":"https://api.github.com/repos/pusher/pusher-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pusher/pusher-js/issues/128/comments","statuses_url":"https://api.github.com/repos/pusher/pusher-js/statuses/e5ad496a975e9fbf401bae2f31471934b3e50f25","head":{"label":"pusher:runtime-abstraction","ref":"runtime-abstraction","sha":"e5ad496a975e9fbf401bae2f31471934b3e50f25","user":{"login":"pusher","id":739550,"avatar_url":"https://avatars.githubusercontent.com/u/739550?v=3","gravatar_id":"","url":"https://api.github.com/users/pusher","html_url":"https://github.com/pusher","followers_url":"https://api.github.com/users/pusher/followers","following_url":"https://api.github.com/users/pusher/following{/other_user}","gists_url":"https://api.github.com/users/pusher/gists{/gist_id}","starred_url":"https://api.github.com/users/pusher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pusher/subscriptions","organizations_url":"https://api.github.com/users/pusher/orgs","repos_url":"https://api.github.com/users/pusher/repos","events_url":"https://api.github.com/users/pusher/events{/privacy}","received_events_url":"https://api.github.com/users/pusher/received_events","type":"Organization","site_admin":false},"repo":{"id":617902,"name":"pusher-js","full_name":"pusher/pusher-js","owner":{"login":"pusher","id":739550,"avatar_url":"https://avatars.githubusercontent.com/u/739550?v=3","gravatar_id":"","url":"https://api.github.com/users/pusher","html_url":"https://github.com/pusher","followers_url":"https://api.github.com/users/pusher/followers","following_url":"https://api.github.com/users/pusher/following{/other_user}","gists_url":"https://api.github.com/users/pusher/gists{/gist_id}","starred_url":"https://api.github.com/users/pusher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pusher/subscriptions","organizations_url":"https://api.github.com/users/pusher/orgs","repos_url":"https://api.github.com/users/pusher/repos","events_url":"https://api.github.com/users/pusher/events{/privacy}","received_events_url":"https://api.github.com/users/pusher/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pusher/pusher-js","description":"Pusher Javascript library","fork":false,"url":"https://api.github.com/repos/pusher/pusher-js","forks_url":"https://api.github.com/repos/pusher/pusher-js/forks","keys_url":"https://api.github.com/repos/pusher/pusher-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pusher/pusher-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pusher/pusher-js/teams","hooks_url":"https://api.github.com/repos/pusher/pusher-js/hooks","issue_events_url":"https://api.github.com/repos/pusher/pusher-js/issues/events{/number}","events_url":"https://api.github.com/repos/pusher/pusher-js/events","assignees_url":"https://api.github.com/repos/pusher/pusher-js/assignees{/user}","branches_url":"https://api.github.com/repos/pusher/pusher-js/branches{/branch}","tags_url":"https://api.github.com/repos/pusher/pusher-js/tags","blobs_url":"https://api.github.com/repos/pusher/pusher-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pusher/pusher-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pusher/pusher-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/pusher/pusher-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pusher/pusher-js/statuses/{sha}","languages_url":"https://api.github.com/repos/pusher/pusher-js/languages","stargazers_url":"https://api.github.com/repos/pusher/pusher-js/stargazers","contributors_url":"https://api.github.com/repos/pusher/pusher-js/contributors","subscribers_url":"https://api.github.com/repos/pusher/pusher-js/subscribers","subscription_url":"https://api.github.com/repos/pusher/pusher-js/subscription","commits_url":"https://api.github.com/repos/pusher/pusher-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/pusher/pusher-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/pusher/pusher-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/pusher/pusher-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/pusher/pusher-js/contents/{+path}","compare_url":"https://api.github.com/repos/pusher/pusher-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pusher/pusher-js/merges","archive_url":"https://api.github.com/repos/pusher/pusher-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pusher/pusher-js/downloads","issues_url":"https://api.github.com/repos/pusher/pusher-js/issues{/number}","pulls_url":"https://api.github.com/repos/pusher/pusher-js/pulls{/number}","milestones_url":"https://api.github.com/repos/pusher/pusher-js/milestones{/number}","notifications_url":"https://api.github.com/repos/pusher/pusher-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pusher/pusher-js/labels{/name}","releases_url":"https://api.github.com/repos/pusher/pusher-js/releases{/id}","created_at":"2010-04-19T15:04:12Z","updated_at":"2015-10-02T06:37:48Z","pushed_at":"2015-10-04T11:25:52Z","git_url":"git://github.com/pusher/pusher-js.git","ssh_url":"git@github.com:pusher/pusher-js.git","clone_url":"https://github.com/pusher/pusher-js.git","svn_url":"https://github.com/pusher/pusher-js","homepage":"http://pusher.com","size":4479,"stargazers_count":430,"watchers_count":430,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":106,"mirror_url":null,"open_issues_count":16,"forks":106,"open_issues":16,"watchers":430,"default_branch":"master"}},"base":{"label":"pusher:master","ref":"master","sha":"c492fbb1c44c08627fc44621fd3e7f7db1ba51f5","user":{"login":"pusher","id":739550,"avatar_url":"https://avatars.githubusercontent.com/u/739550?v=3","gravatar_id":"","url":"https://api.github.com/users/pusher","html_url":"https://github.com/pusher","followers_url":"https://api.github.com/users/pusher/followers","following_url":"https://api.github.com/users/pusher/following{/other_user}","gists_url":"https://api.github.com/users/pusher/gists{/gist_id}","starred_url":"https://api.github.com/users/pusher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pusher/subscriptions","organizations_url":"https://api.github.com/users/pusher/orgs","repos_url":"https://api.github.com/users/pusher/repos","events_url":"https://api.github.com/users/pusher/events{/privacy}","received_events_url":"https://api.github.com/users/pusher/received_events","type":"Organization","site_admin":false},"repo":{"id":617902,"name":"pusher-js","full_name":"pusher/pusher-js","owner":{"login":"pusher","id":739550,"avatar_url":"https://avatars.githubusercontent.com/u/739550?v=3","gravatar_id":"","url":"https://api.github.com/users/pusher","html_url":"https://github.com/pusher","followers_url":"https://api.github.com/users/pusher/followers","following_url":"https://api.github.com/users/pusher/following{/other_user}","gists_url":"https://api.github.com/users/pusher/gists{/gist_id}","starred_url":"https://api.github.com/users/pusher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pusher/subscriptions","organizations_url":"https://api.github.com/users/pusher/orgs","repos_url":"https://api.github.com/users/pusher/repos","events_url":"https://api.github.com/users/pusher/events{/privacy}","received_events_url":"https://api.github.com/users/pusher/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pusher/pusher-js","description":"Pusher Javascript library","fork":false,"url":"https://api.github.com/repos/pusher/pusher-js","forks_url":"https://api.github.com/repos/pusher/pusher-js/forks","keys_url":"https://api.github.com/repos/pusher/pusher-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pusher/pusher-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pusher/pusher-js/teams","hooks_url":"https://api.github.com/repos/pusher/pusher-js/hooks","issue_events_url":"https://api.github.com/repos/pusher/pusher-js/issues/events{/number}","events_url":"https://api.github.com/repos/pusher/pusher-js/events","assignees_url":"https://api.github.com/repos/pusher/pusher-js/assignees{/user}","branches_url":"https://api.github.com/repos/pusher/pusher-js/branches{/branch}","tags_url":"https://api.github.com/repos/pusher/pusher-js/tags","blobs_url":"https://api.github.com/repos/pusher/pusher-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pusher/pusher-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pusher/pusher-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/pusher/pusher-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pusher/pusher-js/statuses/{sha}","languages_url":"https://api.github.com/repos/pusher/pusher-js/languages","stargazers_url":"https://api.github.com/repos/pusher/pusher-js/stargazers","contributors_url":"https://api.github.com/repos/pusher/pusher-js/contributors","subscribers_url":"https://api.github.com/repos/pusher/pusher-js/subscribers","subscription_url":"https://api.github.com/repos/pusher/pusher-js/subscription","commits_url":"https://api.github.com/repos/pusher/pusher-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/pusher/pusher-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/pusher/pusher-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/pusher/pusher-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/pusher/pusher-js/contents/{+path}","compare_url":"https://api.github.com/repos/pusher/pusher-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pusher/pusher-js/merges","archive_url":"https://api.github.com/repos/pusher/pusher-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pusher/pusher-js/downloads","issues_url":"https://api.github.com/repos/pusher/pusher-js/issues{/number}","pulls_url":"https://api.github.com/repos/pusher/pusher-js/pulls{/number}","milestones_url":"https://api.github.com/repos/pusher/pusher-js/milestones{/number}","notifications_url":"https://api.github.com/repos/pusher/pusher-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pusher/pusher-js/labels{/name}","releases_url":"https://api.github.com/repos/pusher/pusher-js/releases{/id}","created_at":"2010-04-19T15:04:12Z","updated_at":"2015-10-02T06:37:48Z","pushed_at":"2015-10-04T11:25:52Z","git_url":"git://github.com/pusher/pusher-js.git","ssh_url":"git@github.com:pusher/pusher-js.git","clone_url":"https://github.com/pusher/pusher-js.git","svn_url":"https://github.com/pusher/pusher-js","homepage":"http://pusher.com","size":4479,"stargazers_count":430,"watchers_count":430,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":106,"mirror_url":null,"open_issues_count":16,"forks":106,"open_issues":16,"watchers":430,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pusher/pusher-js/pulls/128"},"html":{"href":"https://github.com/pusher/pusher-js/pull/128"},"issue":{"href":"https://api.github.com/repos/pusher/pusher-js/issues/128"},"comments":{"href":"https://api.github.com/repos/pusher/pusher-js/issues/128/comments"},"review_comments":{"href":"https://api.github.com/repos/pusher/pusher-js/pulls/128/comments"},"review_comment":{"href":"https://api.github.com/repos/pusher/pusher-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pusher/pusher-js/pulls/128/commits"},"statuses":{"href":"https://api.github.com/repos/pusher/pusher-js/statuses/e5ad496a975e9fbf401bae2f31471934b3e50f25"}}}}