{"id":34719852,"url":"https://github.com/explodes/sock-share","last_synced_at":"2026-05-23T08:34:37.351Z","repository":{"id":11424718,"uuid":"13876924","full_name":"explodes/sock-share","owner":"explodes","description":"Pair two clients together via websockets","archived":false,"fork":false,"pushed_at":"2013-10-26T04:57:39.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-14T05:15:30.372Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/explodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-26T03:03:52.000Z","updated_at":"2013-10-28T15:57:42.000Z","dependencies_parsed_at":"2022-09-19T05:30:20.442Z","dependency_job_id":null,"html_url":"https://github.com/explodes/sock-share","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/explodes/sock-share","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explodes%2Fsock-share","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explodes%2Fsock-share/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explodes%2Fsock-share/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explodes%2Fsock-share/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/explodes","download_url":"https://codeload.github.com/explodes/sock-share/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explodes%2Fsock-share/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33389225,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T04:15:53.637Z","status":"ssl_error","status_checked_at":"2026-05-23T04:15:53.242Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-25T01:43:26.498Z","updated_at":"2026-05-23T08:34:37.343Z","avatar_url":"https://github.com/explodes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"sock-share\n==========\n\nPair two clients together via websockets.\n\n\nLets say your favorite browser can be controlled by your favorite phone.\nYou need to make a connection somehow.\n\n# Enter webshare.js\n\nclass WebShare\n--------------\n\nThis class contains the functionality for pairing, unparing, and relaying information to its paired partner.\nCallbacks are used to handle this functionality.\nHandling relays is up to client implemenations.\n\n\n### Constructors:\n\n#### `new WebShare(host, port, debugMode=false)`\n\nConstruct a new instance connection to `host` and `port` optionally enabling `debugMode` which just enables logging.\n\n### Properties:\n\n#### `onrelay`\nCallback function when data is relayed to us from our paired partner.\n\n\nSignature: `function(true, 'RELAY_OK', packageObject)`\n\n#### `oncommanderror`\nCallback function when the underlying framework fails to support itself.\nClients do not need to worry about this, although it may help with debugging.\n\n\nSignature: `function(false, 'COMMAND_ERROR', {error: message})`\n\n#### `onunpair`\nCallback function when unpairing happens involuntarily, either the paired partner disconnected by error or gracefully.\n\n\nSignature: `function(true, 'SUCCESS', null)`\n\n#### `key`\nIdentification of this WebShare instance, used for pairing\n\n#### `pairedTo`\nIdentification of the paired partner\n\n#### `debug`\nShow logging messages\n\n### Methods:\n\nAll callbacks are in the form of `function(success, code, body)`\n\n#### `pair(key, callback)`\nPair this `WebShare` with another. Pairing with or to an already paired or non-existant partner will result in an error code. You cannot pair with yourself.\n\n#### `unpair(callback)`\nUnpair this `WebShare` from its partner. Unpairing unpaired `WebShares` will result in error.\n\n#### `relay(data, callback)`\nRelay information to the paired partner. The callback will be called but the data sent will not be included.\n\n#### `getKey(callback)`\nSimply acquires this `WebShare`'s key from the server. This happens automatically on instantiation, although it is not instant. Get the key by accessing the `key` property.\n\n### `close()`\nClose the underlying WebSocket.\n\n\n### Example\n\nHere is an example of Alice pairing with Bob.\n\n\n\n```\nfunction logger(name, action) {\n    return function(success, code, body) {\n        console.log(name, action, success, code, body);\n    }\n}\n\nvar debug = false;\n\nvar alice = new WebShare('192.168.1.3', 9000, debug);\nvar bob = new WebShare('192.168.1.3', 9000, debug);\n\nalice.oncommanderror = logger('Alice', 'oncommanderror');\nalice.onunpair = logger('Alice', 'onunpair');\nalice.onrelay = logger('Alice', 'onrelay');\n\nbob.oncommanderror = logger('Bob', 'oncommanderror');\nbob.onunpair = logger('Bob', 'onunpair');\nbob.onrelay = function(success, code, body) {\n    logger('bob', 'onrelay')(success, code, body);\n    var name = body.hello;\n    if (name != bob) {\n        bob.relay('my name isnt ' + name + ' its bob!');\n    } else {\n        bob.relay([123, 'hello alice!']); // can relay anything\n    }\n}\n\n\nfunction testThem() {\n    alice.pair(bob.key, function(success, code, body) {\n        if (!success) { return; }\n        console.log('Alice (' + alice.key + ') is paired to Bob (' + alice.pairedTo + ')');\n        alice.relay({hello: 'dan'}, function(success, code, body) {\n            console.log('Alice is done with the relay');\n        });\n    });\n}\n\nsetTimeout(testThem, 1000); // wait for each person to obtain their keys so that they can be paired in code.\n```\n\nThat example puts the following in the console:\n\n```\nAlice (ae4321aa) is paired to Bob (c9053d5b)\nbob onrelay true RELAY_OK Object {hello: \"dan\"}\nAlice is done with the relay\nAlice onrelay true RELAY_OK my name isnt dan its bob!\n```\n\n\nRunning the server\n------------------\n\nTODO: Make a more portable way...\n\n./manage.py share_server (As a django app)\n------------------------------------------\n\nFirst, run the share server:\n\n```\n./manage.py share_server --host=192.168.1.3 --port=9000\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexplodes%2Fsock-share","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexplodes%2Fsock-share","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexplodes%2Fsock-share/lists"}