{"_id":"@asanrom/webrtc-cdn-client","name":"@asanrom/webrtc-cdn-client","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@asanrom/webrtc-cdn-client","version":"1.0.0","description":"WebRTC CDN client for the browser.","main":"dist/index.js","typings":"dist/index.d.ts","homepage":"https://github.com/AgustinSRG/webrtc-cdn-client","repository":{"type":"git","url":"git+https://github.com/AgustinSRG/webrtc-cdn-client.git"},"scripts":{"prebuild":"npm run lint","compile":"tsc --pretty --declaration && webpack","build":"rimraf dist && npm run compile && npm run gendoc","lint":"eslint --fix src/**/*.ts","test":"http-server -a 127.0.0.1","gendoc":"typedoc --out docs ./src"},"author":{"name":"Agustin San Roman","email":"agustinsanromanguzman@gmail.com","url":"https://github.com/AgustinSRG"},"engines":{"node":">= 12.0.0"},"pre-commit":["lint"],"devDependencies":{"@types/node":"18.0.6","@typescript-eslint/eslint-plugin":"5.30.7","@typescript-eslint/parser":"5.30.7","eslint":"8.20.0","http-server":"14.1.1","rimraf":"3.0.2","ts-loader":"9.3.1","typedoc":"0.23.8","typescript":"4.7.4","webpack":"5.73.0","webpack-cli":"4.10.0"},"license":"MIT","gitHead":"bddd1e048db0d4da13079926856add8fca6b3225","bugs":{"url":"https://github.com/AgustinSRG/webrtc-cdn-client/issues"},"_id":"@asanrom/webrtc-cdn-client@1.0.0","_nodeVersion":"14.17.5","_npmVersion":"8.5.5","dist":{"integrity":"sha512-oQpXYB9W74zQz8YSH4iwRkh6kceUUD5BsZkxOTxLl6tAibE3sDOwVYht6G802T1qkDX0mH1L1aGx5JR4dJ2avw==","shasum":"8139b75c1bd0eacf0266ed32864a71e5a49d7580","tarball":"https://registry.npmjs.org/@asanrom/webrtc-cdn-client/-/webrtc-cdn-client-1.0.0.tgz","fileCount":13,"unpackedSize":26472,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEIj/fM+jxDjIhvdwf9ia9ho63oi1ke9pd0u9gpNhiNeAiAaMF8s1Y4rTPlz9/ZbwLEK/Xt4ryzNBV7uPp0DsMBk6Q=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjEIjmACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqY3w/+MslsiNaz3zvxHo8ni/SR4OsEwGLNIMKLzh5O9ZdnICvqiwv+\r\nPAX9QHsyr8czHUaUc/sVI7QqoERaqoPhAQMRSykBaCCwmanQiUYgE8iNayUy\r\njH5y7eLruQ71kAmP7c+ytIRKJ6kbOgR1a4NkErw04Htu7N5bwBjry3Y15T+l\r\nIog+L49tyH8/hwuQ/h+j+RpmetjtkldqGqbO7MAqGqsnYCnitHBv5URbt+g8\r\nzHwjZOHa3s3g/Q+tPH07yQYDNqq9qyjI0ffN7i4I45N+Zhn9I20MxI9GkL7S\r\ne2htQOd7E+dDBmKuSjm2DmaygM3TCvUDZg26kRjGTb0/+IIsrKQw9woMW4so\r\nYrV1T3hj9HvMuLNXc1WteBwZDZ4ijKXWM2dfvpojIp3bkWN+DbdNvR2HGOr+\r\nZ9m5RBbi0ofgLRant1E22riGB0GaIVlnKMts7lxjSS3bxHOBnYka4jBJEjKM\r\nOXdfndtH96igjRFrmScWFxEMcWH0B1KIEirQ6wpM5Yq5KhbDJOtjNxVMz9fg\r\nS1cF4425qpASYReiYw/9IKbOPLL3P1lIIcx2CzeSg55JicntE3ywLUWD7iPL\r\npldLfXG9OKpnBTF5naDdG10xJKbnOyhs0IuSWC2ep70zj8Q3GMcK5g5jweOr\r\nACjNu0nAHPMDoCdy//OtSTbd37C7XThohl4=\r\n=sjKr\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"asanrom","email":"agustinsanromanguzman@gmail.com"},"directories":{},"maintainers":[{"name":"asanrom","email":"agustinsanromanguzman@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/webrtc-cdn-client_1.0.0_1662028006225_0.7550782705056813"},"_hasShrinkwrap":false}},"time":{"created":"2022-09-01T10:26:46.151Z","1.0.0":"2022-09-01T10:26:46.438Z","modified":"2022-09-01T10:26:46.567Z"},"maintainers":[{"name":"asanrom","email":"agustinsanromanguzman@gmail.com"}],"description":"WebRTC CDN client for the browser.","homepage":"https://github.com/AgustinSRG/webrtc-cdn-client","repository":{"type":"git","url":"git+https://github.com/AgustinSRG/webrtc-cdn-client.git"},"author":{"name":"Agustin San Roman","email":"agustinsanromanguzman@gmail.com","url":"https://github.com/AgustinSRG"},"bugs":{"url":"https://github.com/AgustinSRG/webrtc-cdn-client/issues"},"license":"MIT","readme":"# WebRTC CDN Client\r\n\r\n[![npm version](https://badge.fury.io/js/%40asanrom%2Fwebrtc-cdn-client.svg)](https://badge.fury.io/js/%40asanrom%2Fwebrtc-cdn-client)\r\n\r\nJavascript client for [webrtc-cdn](https://github.com/AgustinSRG/webrtc-cdn).\r\n\r\n## Installation\r\n\r\nIf you are using a npm managed project use:\r\n\r\n```\r\nnpm install @asanrom/webrtc-cdn-client\r\n```\r\n\r\nIf you are using it in the browser, download the minified file from the [Releases](https://github.com/AgustinSRG/webrtc-cdn-client/tags) section and import it to your html:\r\n\r\n```html\r\n<script type=\"text/javascript\" src=\"/path/to/webrtc-cdn-client.js\"></script>\r\n```\r\n\r\n## Usage\r\n\r\n```js\r\n// Websocket connection URL\r\nconst wsURL = \"ws://localhost/ws\";\r\n\r\n// RTC configuration\r\nconst rtcConfig = {\r\n    \"iceServers\": [\r\n        { \"urls\": \"stun:stun.l.google.com:19302\" }\r\n    ],\r\n    \"sdpSemantics\": \"unified-plan\"\r\n};\r\n\r\n// Create a client to connect to WebRTC CDN\r\nconst client = new WebRTC_CDN.WebRTCClient(wsURL, rtcConfig);\r\n\r\nclient.on('open', () => {\r\n    // Emitted when client connects to the WebRTC CDN node\r\n    publishCamera(); // or playCamera()\r\n});\r\n\r\nclient.on('close', () => {\r\n    // Emitted when client connection close\r\n    // You could reconnect or finish the session\r\n});\r\n\r\nclient.on('error', e => {\r\n    // Error messages such as connection errors\r\n    console.error(e);\r\n});\r\n\r\nclient.on('send', m => {\r\n    // For debug purposes, you can log outgoing messages with the 'send' event\r\n    console.log(\">>> \" + JSON.stringify(m));\r\n});\r\n\r\nclient.on('message', m => {\r\n    // For debug purposes, you can log incoming messages with the 'message' event\r\n    console.log(\"<<< \" + JSON.stringify(m));\r\n});\r\n\r\n\r\nfunction publishCamera() {\r\n    navigator.mediaDevices.getUserMedia({video: true, audio: true}).then((stream) => {\r\n        const req = client.publish(\r\n            stream, // Media Stream to publish\r\n            \"camera\", // Stream ID, needed also for other clients to play the stream\r\n            \"\" // Authentication token (if required)\r\n        );\r\n\r\n        req.on('ok', () => {\r\n            // Request success (after this, the publishing will start via WebRTC)\r\n        });\r\n\r\n        req.on('peer-connection-state-change', state => {\r\n            // You can track the peer connection state with this event\r\n            console.log(\"PeerConnection State: \" + state);\r\n        });\r\n\r\n        req.on('error', e => {\r\n            // Could not publish\r\n            alert(\"Error: \" + e.code + \" / \" + e.message);\r\n        });\r\n\r\n        req.on('close', () => {\r\n            // Request closed\r\n        });\r\n    });\r\n}\r\n\r\nfunction playCamera() {\r\n    const req = client.play(\r\n        \"camera\", // Stream ID to play\r\n        \"\" // Authentication token (if required)\r\n    );\r\n\r\n    req.on('ok', () => {\r\n        // Request success (after this, the play will start via WebRTC)\r\n    });\r\n\r\n    req.on('standby', () => {\r\n        // The stream is in STANDBY mode\r\n        // This means there is no peer publishing yet\r\n        // By default, the request will be waiting until a stream starts\r\n        document.getElementById(\"test_video\").pause();\r\n        document.getElementById(\"test_video\").srcObject = null;\r\n    });\r\n\r\n    req.on('stream', (mediaStream) => {\r\n        // Received playable media stream\r\n        // You may add it to some video element to show for the user\r\n        document.getElementById(\"test_video\").srcObject = mediaStream;\r\n        document.getElementById(\"test_video\").play();\r\n    });\r\n\r\n    req.on('peer-connection-state-change', state => {\r\n        // You can track the peer connection state with this event\r\n        console.log(\"PeerConnection State: \" + state);\r\n    });\r\n\r\n    req.on('error', e => {\r\n        // Could not play\r\n        alert(\"Error: \" + e.code + \" / \" + e.message);\r\n    });\r\n\r\n    req.on('close', () => {\r\n        // Request closed\r\n    });\r\n}\r\n\r\n```\r\n\r\n## Documentation\r\n\r\n - [Library documentation (Auto-generated)](https://agustinsrg.github.io/webrtc-cdn-client/)\r\n","readmeFilename":"README.md"}