├── .gitignore ├── package.json ├── README.md ├── LICENSE └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | sandbox.js 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hyperphone", 3 | "version": "1.0.0", 4 | "description": "A telephone over Hyperbeam", 5 | "main": "index.js", 6 | "bin": { 7 | "hyperphone": "index.js" 8 | }, 9 | "dependencies": { 10 | "hyperbeam": "^1.1.1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/mafintosh/hyperphone.git" 15 | }, 16 | "author": "Mathias Buus (@mafintosh)", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/mafintosh/hyperphone/issues" 20 | }, 21 | "homepage": "https://github.com/mafintosh/hyperphone" 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hyperphone 2 | 3 | A telephone over [Hyperbeam](https://github.com/mafintosh/hyperbeam) 4 | 5 | ``` 6 | npm install -g hyperphone 7 | ``` 8 | 9 | Needs sox installed. 10 | 11 | On mac: 12 | 13 | ```sh 14 | brew install sox 15 | ``` 16 | 17 | On linux: 18 | 19 | ```sh 20 | sudo apt-get install sox 21 | ``` 22 | 23 | ## Usage 24 | 25 | On your computer 26 | 27 | ```sh 28 | hyperphone "your name and your friend" 29 | ``` 30 | 31 | On your friends 32 | 33 | ```sh 34 | hyperphone "your name and your friend" 35 | ``` 36 | 37 | Now your mic will be streamed to your friends audio and vice versa! 38 | 39 | ## License 40 | 41 | MIT 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Mathias Buus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const Hyperbeam = require('hyperbeam') 4 | const { spawn } = require('child_process') 5 | 6 | if (process.argv.length < 3) { 7 | console.error('Usage: hyperphone ') 8 | process.exit(1) 9 | } 10 | 11 | let record 12 | let play 13 | 14 | const beam = new Hyperbeam('hyperphone ' + process.argv.slice(2).join(' ')) 15 | 16 | beam.on('remote-address', function ({ host, port }) { 17 | if (!host) console.error('[hyperbeam] Could not detect remote address') 18 | else console.error('[hyperbeam] Joined the DHT - remote address is ' + host + ':' + port) 19 | if (port) console.error('[hyperbeam] Network is holepunchable \\o/') 20 | }) 21 | 22 | beam.on('connected', function () { 23 | console.error('[hyperbeam] Success! Encrypted tunnel established to remote peer') 24 | record = spawn('sox', ['-q', '--buffer', '512', '-d', '-r', '44100', '-c', '1', '-e', 'signed-integer', '-b', '16', '-t', 'wav', '-'], { 25 | stdio: ['inherit', 'pipe', 'inherit' ] 26 | }) 27 | play = spawn('play', ['-q', '--buffer', '512', '-'], { 28 | stdio: ['pipe', 'inherit', 'inherit' ] 29 | }) 30 | record.stdout.pipe(beam).pipe(play.stdin) 31 | }) 32 | 33 | beam.on('end', () => { 34 | beam.end() 35 | if (record) record.kill() 36 | if (play) play.kill() 37 | }) 38 | 39 | beam.resume() 40 | beam.pause() 41 | 42 | process.once('SIGINT', () => { 43 | if (record) record.kill() 44 | if (play) play.kill() 45 | if (!beam.connected) closeASAP() 46 | else beam.end() 47 | }) 48 | 49 | function closeASAP () { 50 | console.error('[hyperbeam] Shutting down beam...') 51 | 52 | const timeout = setTimeout(() => process.exit(1), 2000) 53 | beam.destroy() 54 | beam.on('close', function () { 55 | clearTimeout(timeout) 56 | }) 57 | } 58 | --------------------------------------------------------------------------------