{"id":13760858,"url":"https://github.com/HadiModarres/MeshP2P","last_synced_at":"2025-05-10T11:32:04.491Z","repository":{"id":40498411,"uuid":"201632558","full_name":"HadiModarres/MeshP2P","owner":"HadiModarres","description":"Create P2P apps between browsers","archived":false,"fork":false,"pushed_at":"2022-12-30T18:47:06.000Z","size":8524,"stargazers_count":13,"open_issues_count":15,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-16T18:34:11.007Z","etag":null,"topics":["browser","decentralized","discovery","distributed","distributed-systems","framework","gossip","gossip-protocol","mesh-networks","network","p2p","p2p-apps","p2p-network","peer-to-peer","proximity","rtc","search","searchable","vicinity","webrtc"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/HadiModarres.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":"2019-08-10T13:16:07.000Z","updated_at":"2024-01-04T22:13:01.000Z","dependencies_parsed_at":"2023-01-31T13:30:58.893Z","dependency_job_id":null,"html_url":"https://github.com/HadiModarres/MeshP2P","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HadiModarres%2FMeshP2P","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HadiModarres%2FMeshP2P/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HadiModarres%2FMeshP2P/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HadiModarres%2FMeshP2P/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HadiModarres","download_url":"https://codeload.github.com/HadiModarres/MeshP2P/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253410685,"owners_count":21904129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["browser","decentralized","discovery","distributed","distributed-systems","framework","gossip","gossip-protocol","mesh-networks","network","p2p","p2p-apps","p2p-network","peer-to-peer","proximity","rtc","search","searchable","vicinity","webrtc"],"created_at":"2024-08-03T13:01:24.562Z","updated_at":"2025-05-10T11:32:04.206Z","avatar_url":"https://github.com/HadiModarres.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\n\n\n\u003ca href=\"https://meshp2p.org\"\u003e\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/3/3c/NetworkTopology-FullyConnected.png\" height=\"150\" align=\"right\"\u003e\u003c/a\u003e\n# MeshP2P\n#### Create P2P apps between browsers\n\nMeshP2P is a framework that allows bootstrapping the development of a distributed application over web browsers using WebRTC. \nIt allows for discovery of other peers without requiring a central server. This is done through regular exchange of information between peers. \n\n\n## Usage\n```\nnpm install meshp2p --save\n```\n\n#### Importing in your js code\n```\nconst Node = require(\"meshp2p\").Node;\n```\n\n## API\n\n\n### Node Constructor\nAs a minimum a callback for incoming rtc connections, and an array of signalling servers should be provided to the Node constructor. \n\n##### Arguments\n1. InboundCb (func): a function that is called when another peer makes a connection to this node. The rtcDataChannel will provided \nas an argument to the callback function. \n2. Options (Obj): parameters, DEFAULT_SIGNALLING_SERVERS is required\n\n##### Example\nAssuming two signalling servers are running locally on ports 12345 and 12346:\n```\n   node = new Node((rtcDataChannel)=\u003e{\n            // do something with inbound connection\n        },{DEFAULT_SIGNALLING_SERVERS:[\n                {\n                    \"socket\": {\n                        \"server\": \"http://127.0.0.1:12345\"\n                    },\n                    \"signallingApiBase\": \"http://127.0.0.1:12345\"\n                },\n                {\n                    \"socket\": {\n                        \"server\": \"http://127.0.0.1:12346\"\n                    },\n                    \"signallingApiBase\": \"http://127.0.0.1:12346\"\n                }\n            ]});\n```\n\nSee [Signalling Servers](#signalling-servers) on how to start signalling servers.\n\n### registerList\n\nMeshP2P allows for multiple lists to exist in the network, and each node is able to register multiple entries in each list.\nMake a global list in the network using registerList. \n\n##### Arguments\n1. list (string): The name of the list\n2. proximityFunction (func): The proximity function specifies how closeness between nodes is defined. \nIt has the form (entry1, entry2) =\u003e float. The higher returned score from proximity function means the \ntwo entries are more identical, and a score of 0 means least identical. \n3. responseMinScore (float): this is the minimum closeness score between entries to consider it a hit, and a node would respond to the query. \n\n##### Returns\n\nVoid.\n\n##### Example 1\n\nConsider a network with a list of names of peers. In this case it's natural to consider closeness between entries to be string similarity:\n\n\n```\nregisterList(\"list#name\", (str1, str2) =\u003e {return stringSimilarity(str1,str2)}, 0.7)\n```\n\n##### Example 2\n\nConsider a network of peers with each peer having a coordinate in 2D space. In this case one can define the closeness to be inverse of their euclidean distance, and a distance of less than 4 to consider a hit: \n\n```\nregisterList(\"list#coordinates\", (entry1,entry2) =\u003e {return 1/euclideanDist(entry1,entry2)}, 1/4)\n```\n\n### setEntries\n\nSet the entries for the current node in the specified network list.\n\n##### Arguments\n1. list (string): The global list\n2. entries (object[]): the entries for this node \n\n##### Returns\nVoid.  \n\n##### Examples\n```\nsetEntries(\"list#names\", [\"Jack\"])\n```\n\n```\nsetEntries(\"list#coordinates\",[{x: 3,y:12}])\n```\n\n### Search\n\nSearch the network. \n\n##### Arguments\n1. list(string): The global list to search\n2. query(obj): The query. The query should have the form of list entry, and will be fed to the provided proximityFunction provided. \n3. timeout(int): Number of seconds to wait for responses from the network. After that, the resources are freed and responses for this query aren't handled. \n4. searchResultCallback(func): The callback is called each time a response is received from the network. The response is passed to the callback function and has the form: {key,value}. key is the entry that caused a match, and the value is the nodePointer of the peer that has responded to the query. \n\n##### Examples\n```\nsearch(\"list#names\", \"jacky\", 60, (response)=\u003e{\n// do something with the response\n});\n```\n\n```\nsearch(\"list#coordinates\", {x:2,y:2}, 60, (response)=\u003e{\n// do something with the response\n});\n```\n\n### connectToNode\n\n##### Arguments\nnodePointer(nodePointerObj): The node pointer of the peer to connect to.\n\n##### Returns\nA promise that is resolved with an rtcDataChannel (https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel) when successfully connected to the target peer.\n\n##### Examples\n\n```\nnode.search(\"list#names\", \"jacky\", 60, (response)=\u003e{\n   node.connectToNode(response.value).then(rtcDataChannel)=\u003e{\n       rtcDataChannel.send(\"hello\"); }) \n});\n```\n\n### startNode\nStarts the node. Start node only after specifying the global list and the node's entries in the list. \n\n##### Arguments\nNone\n\n\n## Signalling Servers\n\nWebRTC requires the use of signalling servers so that peers can negotiate for a connection. Signalling servers are provided as part of MeshP2P\nand can be easily started using:\n```\nnpm run server -- 12345\n```\nThis runs a signalling server on port:12345\n\nPeers in the network should have access to at least one signalling server, and this should be specified in the node constructor when \ncreating peers. \n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHadiModarres%2FMeshP2P","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHadiModarres%2FMeshP2P","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHadiModarres%2FMeshP2P/lists"}