{"action":"created","comment":{"url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/comments/75308039","id":75308039,"diff_hunk":"@@ -1,147 +1,53 @@\n 'use strict'\n \n-const debug = require('debug')\n-const log = debug('libp2p:websockets')\n-const SW = require('simple-websocket')\n-const isNode = require('detect-node')\n-let SWS\n-if (isNode) {\n-  SWS = require('simple-websocket-server')\n-} else {\n-  SWS = {}\n-}\n+const connect = require('pull-ws/client')\n const mafmt = require('mafmt')\n const contains = require('lodash.contains')\n const Connection = require('interface-connection').Connection\n+const debug = require('debug')\n+const log = debug('libp2p:websockets:dialer')\n \n-const CLOSE_TIMEOUT = 2000\n-// const IPFS_CODE = 421\n-\n-exports = module.exports = WebSockets\n-\n-function WebSockets () {\n-  if (!(this instanceof WebSockets)) {\n-    return new WebSockets()\n-  }\n+const createListener = require('./listener')\n \n-  this.dial = function (ma, options, callback) {\n+module.exports = class WebSockets {\n+  dial (ma, options, cb) {\n     if (typeof options === 'function') {\n-      callback = options\n+      cb = options\n       options = {}\n     }\n \n-    if (!callback) {\n-      callback = function noop () {}\n+    if (!cb) {\n+      cb = () => {}\n     }\n \n     const maOpts = ma.toOptions()\n \n-    const socket = new SW('ws://' + maOpts.host + ':' + maOpts.port)\n-\n-    const conn = new Connection(socket)\n-\n-    socket.on('timeout', () => {\n-      conn.emit('timeout')\n-    })\n-\n-    socket.on('error', (err) => {\n-      callback(err)\n-      conn.emit('error', err)\n-    })\n-\n-    socket.on('connect', () => {\n-      callback(null, conn)\n-      conn.emit('connect')\n-    })\n-\n-    conn.getObservedAddrs = (cb) => {\n+    const url = `ws://${maOpts.host}:${maOpts.port}`\n+    log('dialing %s', url)\n+    const socket = connect(url, cb)\n+    socket.getObservedAddrs = (cb) => {\n       return cb(null, [ma])\n     }\n \n+    const conn = new Connection(socket)","path":"src/index.js","position":74,"original_position":74,"commit_id":"4d4fa5aa7b55245c298e01773d675936b94b4940","original_commit_id":"4d4fa5aa7b55245c298e01773d675936b94b4940","user":{"login":"diasdavid","id":1211152,"avatar_url":"https://avatars.githubusercontent.com/u/1211152?v=3","gravatar_id":"","url":"https://api.github.com/users/diasdavid","html_url":"https://github.com/diasdavid","followers_url":"https://api.github.com/users/diasdavid/followers","following_url":"https://api.github.com/users/diasdavid/following{/other_user}","gists_url":"https://api.github.com/users/diasdavid/gists{/gist_id}","starred_url":"https://api.github.com/users/diasdavid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diasdavid/subscriptions","organizations_url":"https://api.github.com/users/diasdavid/orgs","repos_url":"https://api.github.com/users/diasdavid/repos","events_url":"https://api.github.com/users/diasdavid/events{/privacy}","received_events_url":"https://api.github.com/users/diasdavid/received_events","type":"User","site_admin":false},"body":"Same as https://github.com/libp2p/js-libp2p-tcp/pull/20/files#r75307992","created_at":"2016-08-18T13:33:58Z","updated_at":"2016-08-18T13:33:58Z","html_url":"https://github.com/libp2p/js-libp2p-websockets/pull/18#discussion_r75308039","pull_request_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/comments/75308039"},"html":{"href":"https://github.com/libp2p/js-libp2p-websockets/pull/18#discussion_r75308039"},"pull_request":{"href":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/18","id":80951716,"html_url":"https://github.com/libp2p/js-libp2p-websockets/pull/18","diff_url":"https://github.com/libp2p/js-libp2p-websockets/pull/18.diff","patch_url":"https://github.com/libp2p/js-libp2p-websockets/pull/18.patch","issue_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues/18","number":18,"state":"open","locked":false,"title":"[WIP] Move to pull-streams","user":{"login":"dignifiedquire","id":790842,"avatar_url":"https://avatars.githubusercontent.com/u/790842?v=3","gravatar_id":"","url":"https://api.github.com/users/dignifiedquire","html_url":"https://github.com/dignifiedquire","followers_url":"https://api.github.com/users/dignifiedquire/followers","following_url":"https://api.github.com/users/dignifiedquire/following{/other_user}","gists_url":"https://api.github.com/users/dignifiedquire/gists{/gist_id}","starred_url":"https://api.github.com/users/dignifiedquire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dignifiedquire/subscriptions","organizations_url":"https://api.github.com/users/dignifiedquire/orgs","repos_url":"https://api.github.com/users/dignifiedquire/repos","events_url":"https://api.github.com/users/dignifiedquire/events{/privacy}","received_events_url":"https://api.github.com/users/dignifiedquire/received_events","type":"User","site_admin":false},"body":"Investigate `delay`. Ref https://github.com/pull-stream/pull-ws/issues/13","created_at":"2016-08-11T12:51:06Z","updated_at":"2016-08-18T13:33:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7df1111f9b043c5141541c2d7f8f71a421bd863b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/18/commits","review_comments_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/18/comments","review_comment_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/comments{/number}","comments_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues/18/comments","statuses_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/statuses/4d4fa5aa7b55245c298e01773d675936b94b4940","head":{"label":"libp2p:pull","ref":"pull","sha":"4d4fa5aa7b55245c298e01773d675936b94b4940","user":{"login":"libp2p","id":14838238,"avatar_url":"https://avatars.githubusercontent.com/u/14838238?v=3","gravatar_id":"","url":"https://api.github.com/users/libp2p","html_url":"https://github.com/libp2p","followers_url":"https://api.github.com/users/libp2p/followers","following_url":"https://api.github.com/users/libp2p/following{/other_user}","gists_url":"https://api.github.com/users/libp2p/gists{/gist_id}","starred_url":"https://api.github.com/users/libp2p/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libp2p/subscriptions","organizations_url":"https://api.github.com/users/libp2p/orgs","repos_url":"https://api.github.com/users/libp2p/repos","events_url":"https://api.github.com/users/libp2p/events{/privacy}","received_events_url":"https://api.github.com/users/libp2p/received_events","type":"Organization","site_admin":false},"repo":{"id":52522469,"name":"js-libp2p-websockets","full_name":"libp2p/js-libp2p-websockets","owner":{"login":"libp2p","id":14838238,"avatar_url":"https://avatars.githubusercontent.com/u/14838238?v=3","gravatar_id":"","url":"https://api.github.com/users/libp2p","html_url":"https://github.com/libp2p","followers_url":"https://api.github.com/users/libp2p/followers","following_url":"https://api.github.com/users/libp2p/following{/other_user}","gists_url":"https://api.github.com/users/libp2p/gists{/gist_id}","starred_url":"https://api.github.com/users/libp2p/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libp2p/subscriptions","organizations_url":"https://api.github.com/users/libp2p/orgs","repos_url":"https://api.github.com/users/libp2p/repos","events_url":"https://api.github.com/users/libp2p/events{/privacy}","received_events_url":"https://api.github.com/users/libp2p/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/libp2p/js-libp2p-websockets","description":"JavaScript implementation of the WebSockets module that libp2p uses and that implements the abstract-transport interface ","fork":false,"url":"https://api.github.com/repos/libp2p/js-libp2p-websockets","forks_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/forks","keys_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/teams","hooks_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/hooks","issue_events_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues/events{/number}","events_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/events","assignees_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/assignees{/user}","branches_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/branches{/branch}","tags_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/tags","blobs_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/refs{/sha}","trees_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/statuses/{sha}","languages_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/languages","stargazers_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/stargazers","contributors_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/contributors","subscribers_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/subscribers","subscription_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/subscription","commits_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/commits{/sha}","git_commits_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/commits{/sha}","comments_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/comments{/number}","issue_comment_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues/comments{/number}","contents_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/contents/{+path}","compare_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/merges","archive_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/downloads","issues_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues{/number}","pulls_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls{/number}","milestones_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/milestones{/number}","notifications_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/labels{/name}","releases_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/releases{/id}","deployments_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/deployments","created_at":"2016-02-25T12:21:14Z","updated_at":"2016-06-18T16:22:27Z","pushed_at":"2016-08-12T14:57:03Z","git_url":"git://github.com/libp2p/js-libp2p-websockets.git","ssh_url":"git@github.com:libp2p/js-libp2p-websockets.git","clone_url":"https://github.com/libp2p/js-libp2p-websockets.git","svn_url":"https://github.com/libp2p/js-libp2p-websockets","homepage":null,"size":41,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":4,"forks":2,"open_issues":4,"watchers":1,"default_branch":"master"}},"base":{"label":"libp2p:master","ref":"master","sha":"380c953bd35cca9add0fcb946b31e421ea5b7cb8","user":{"login":"libp2p","id":14838238,"avatar_url":"https://avatars.githubusercontent.com/u/14838238?v=3","gravatar_id":"","url":"https://api.github.com/users/libp2p","html_url":"https://github.com/libp2p","followers_url":"https://api.github.com/users/libp2p/followers","following_url":"https://api.github.com/users/libp2p/following{/other_user}","gists_url":"https://api.github.com/users/libp2p/gists{/gist_id}","starred_url":"https://api.github.com/users/libp2p/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libp2p/subscriptions","organizations_url":"https://api.github.com/users/libp2p/orgs","repos_url":"https://api.github.com/users/libp2p/repos","events_url":"https://api.github.com/users/libp2p/events{/privacy}","received_events_url":"https://api.github.com/users/libp2p/received_events","type":"Organization","site_admin":false},"repo":{"id":52522469,"name":"js-libp2p-websockets","full_name":"libp2p/js-libp2p-websockets","owner":{"login":"libp2p","id":14838238,"avatar_url":"https://avatars.githubusercontent.com/u/14838238?v=3","gravatar_id":"","url":"https://api.github.com/users/libp2p","html_url":"https://github.com/libp2p","followers_url":"https://api.github.com/users/libp2p/followers","following_url":"https://api.github.com/users/libp2p/following{/other_user}","gists_url":"https://api.github.com/users/libp2p/gists{/gist_id}","starred_url":"https://api.github.com/users/libp2p/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libp2p/subscriptions","organizations_url":"https://api.github.com/users/libp2p/orgs","repos_url":"https://api.github.com/users/libp2p/repos","events_url":"https://api.github.com/users/libp2p/events{/privacy}","received_events_url":"https://api.github.com/users/libp2p/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/libp2p/js-libp2p-websockets","description":"JavaScript implementation of the WebSockets module that libp2p uses and that implements the abstract-transport interface ","fork":false,"url":"https://api.github.com/repos/libp2p/js-libp2p-websockets","forks_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/forks","keys_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/teams","hooks_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/hooks","issue_events_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues/events{/number}","events_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/events","assignees_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/assignees{/user}","branches_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/branches{/branch}","tags_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/tags","blobs_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/refs{/sha}","trees_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/statuses/{sha}","languages_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/languages","stargazers_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/stargazers","contributors_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/contributors","subscribers_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/subscribers","subscription_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/subscription","commits_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/commits{/sha}","git_commits_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/git/commits{/sha}","comments_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/comments{/number}","issue_comment_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues/comments{/number}","contents_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/contents/{+path}","compare_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/merges","archive_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/downloads","issues_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues{/number}","pulls_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls{/number}","milestones_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/milestones{/number}","notifications_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/labels{/name}","releases_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/releases{/id}","deployments_url":"https://api.github.com/repos/libp2p/js-libp2p-websockets/deployments","created_at":"2016-02-25T12:21:14Z","updated_at":"2016-06-18T16:22:27Z","pushed_at":"2016-08-12T14:57:03Z","git_url":"git://github.com/libp2p/js-libp2p-websockets.git","ssh_url":"git@github.com:libp2p/js-libp2p-websockets.git","clone_url":"https://github.com/libp2p/js-libp2p-websockets.git","svn_url":"https://github.com/libp2p/js-libp2p-websockets","homepage":null,"size":41,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":4,"forks":2,"open_issues":4,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/18"},"html":{"href":"https://github.com/libp2p/js-libp2p-websockets/pull/18"},"issue":{"href":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues/18"},"comments":{"href":"https://api.github.com/repos/libp2p/js-libp2p-websockets/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/libp2p/js-libp2p-websockets/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/libp2p/js-libp2p-websockets/statuses/4d4fa5aa7b55245c298e01773d675936b94b4940"}}}}
{"actor":{"display_login":"diasdavid"}}