{"id":13527856,"url":"https://github.com/watson/rtsp-stream","last_synced_at":"2025-04-10T05:00:31.915Z","repository":{"id":65412156,"uuid":"42361282","full_name":"watson/rtsp-stream","owner":"watson","description":"A transport agnostic RTSP serial multiplexer module for Node","archived":false,"fork":false,"pushed_at":"2024-07-06T09:03:49.000Z","size":27,"stargazers_count":91,"open_issues_count":7,"forks_count":28,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-30T08:18:51.999Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/watson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-12T15:10:43.000Z","updated_at":"2024-07-03T17:11:25.000Z","dependencies_parsed_at":"2024-09-27T04:24:30.243Z","dependency_job_id":"5546bd18-ec6e-47e1-82fc-4e377302a6e0","html_url":"https://github.com/watson/rtsp-stream","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"3c97d55ae3c2c3f8596026ba1dc7b926a951fcac"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson%2Frtsp-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson%2Frtsp-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson%2Frtsp-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watson%2Frtsp-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/watson","download_url":"https://codeload.github.com/watson/rtsp-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161267,"owners_count":21057554,"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":[],"created_at":"2024-08-01T06:02:03.904Z","updated_at":"2025-04-10T05:00:31.705Z","avatar_url":"https://github.com/watson.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Modules"],"sub_categories":[],"readme":"# rtsp-stream\n\nA transport agnostic RTSP serial multiplexer module for Node. Use it to\nencode or decode RTSP data streams.\n\nThis project aims for 100% compliance with [RFC\n2326](https://tools.ietf.org/html/rfc2326). If you find something\nmissing, please [open an\nissue](https://github.com/watson/rtsp-stream/issues).\n\nProtocol features currently supported:\n\n- Client to server requests/responses\n- Server to client requests/responses\n- Persistent transport connections\n- Connectionless mode (this is just data stream parsing, so sessions\n  must be handled elsewhere)\n- Pipelining\n\nProtocol features that are out of scope for this module:\n\n- Session handling\n\n[![Build status](https://travis-ci.org/watson/rtsp-stream.svg?branch=master)](https://travis-ci.org/watson/rtsp-stream)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)\n\n## Installation\n\n```\nnpm install rtsp-stream\n```\n\n## Usage\n\nLet's set up a TCP server, listen on port 5000 and have it respond to\nRTSP requests:\n\n```js\nvar net = require('net')\nvar rtsp = require('rtsp-stream')\n\nvar server = net.createServer(function (socket) {\n  var decoder = new rtsp.Decoder()\n  var encoder = new rtsp.Encoder()\n\n  decoder.on('request', function (req) {\n    console.log(req.method, req.uri)\n\n    // output the request body\n    req.pipe(process.stdout)\n\n    req.on('end', function () {\n      // prepare a new response to the client\n      var res = encoder.response()\n\n      res.setHeader('CSeq', req.headers['cseq'])\n      res.end('Hello World!')\n    })\n  })\n\n  // pipe the data from the client into the decoder\n  socket.pipe(decoder)\n\n  // ...and pipe the response back to the client from the encoder\n  encoder.pipe(socket)\n})\n\nserver.listen(5000)\n```\n\n### Server -\u003e Client request\n\nIn some scenarios the server will make a request to the client. Here is\nwhat the RFC [have to say](https://tools.ietf.org/html/rfc2326#page-28)\nabout that:\n\n\u003e Unlike HTTP, RTSP allows the media server to send requests to the\n\u003e media client. However, this is only supported for persistent\n\u003e connections, as the media server otherwise has no reliable way of\n\u003e reaching the client. Also, this is the only way that requests from\n\u003e media server to client are likely to traverse firewalls.\n\nIn the example below, the server sends two request to the client using\nthe `Encoder` object:\n\n```js\ndecoder.on('response', function (res) {\n  console.log('Response to CSeq %s (code %s)', res.headers['cseq'], res.statusCode)\n\n  // output the response body\n  res.pipe(process.stdout)\n})\n\nvar body = 'Hello World!'\nvar options = {\n  method: 'OPTIONS',\n  uri: '*',\n  headers: {\n    CSeq: 1,\n    'Content-Length': Buffer.byteLength(body)\n  }\n  body: body\n}\n\nencoder.request(options, function () {\n  console.log('done sending request 1 to client')\n})\n\nvar req = encoder.request({ method: 'OPTIONS', uri: '*' })\nreq.setHeader('CSeq', 2)\nreq.setHeader('Content-Length', Buffer.byteLength(body))\nreq.end(body)\n```\n\n## API\n\nThe rtsp-stream module exposes the following:\n\n- `STATUS_CODES` - List of valid RTSP status codes\n- `Decoder` - The decoder object\n- `Encoder` - The encoder object\n- `IncomingMessage` - A readable stream representing an incoming RTSP\n  message. Can be either a request or a response. Given as the first\n  argument to the `Decoder` request and response event\n- `OutgoingMessage` - A writable stream representing an outgoing RTSP\n  message. Can be either a request or a response\n- `Request` - A writable stream of type `OutgoingMessage` representing\n  an outgoing RTSP request. Generated by `encoder.request()`\n- `Response` - A writable stream of type `OutgoingMessage` representing\n  an outgoing RTSP response. Generated by `encoder.response()`\n\n### `Decoder`\n\nA writable stream used to parse incoming RTSP data. Emits the following\nevents:\n\n#### Event: request\n\nEmitted every time a new request header is found. The event listener is\ncalled with a single arguemnt:\n\n- `req` - An `rtspStream.IncomingMessage` object\n\n#### Event: response\n\nEmitted every time a new response header is found. The event listener is\ncalled with a single arguemnt:\n\n- `res` - An `rtspStream.IncomingMessage` object\n\n### `Encoder`\n\nA readable stream. Outputs valid RTSP responses.\n\n#### `Encoder.response()`\n\nReturns a writable stream of type `Response`.\n\n#### `Encoder.request()`\n\nReturns a writable stream of type `Request`.\n\n### `IncomingMessage`\n\nExposes the body of the incoming RTSP message by implementing a readable\nstream interface.\n\nAlso exposes the RTSP start-line using the following properties:\n\n#### `IncomingMessage.rtspVersion`\n\nThe RTSP protocol version used in the message. By all intents and\npurposes you can expect this to always be `1.0`.\n\n#### `IncomingMessage.method`\n\n*Only used if the message is a request*\n\nThe RTSP request method used in the request. The following are\nstandardized in [RFC 2326](https://tools.ietf.org/html/rfc2326), but\nothers are also used in the wild:\n\n- `DESCRIBE`\n- `ANNOUNCE`\n- `GET_PARAMETER`\n- `OPTIONS`\n- `PAUSE`\n- `PLAY`\n- `RECORD`\n- `SETUP`\n- `SET_PARAMETER`\n- `TEARDOWN`\n\n#### `IncomingMessage.uri`\n\n*Only used if the message is a request*\n\nThe RTSP request URI used.\n\n#### `IncomingMessage.statusCode`\n\n*Only used if the message is a response*\n\nThe RTSP response code used.\n\n#### `IncomingMessage.statusMessage`\n\n*Only used if the message is a response*\n\nThe message matching the RTSP response code used.\n\n#### `IncomingMessage.headers`\n\nAn object containing the headers used on the RTSP request. Object keys\nrepresent header fields and the object values the header values.\n\nAll header field names are lowercased for your convenience.\n\nValues from repeating header fields are joined in an array.\n\n### `OutgoingMessage`\n\nA writable stream representing an outgoing RTSP message. Can be either a\nrequest or a response.\n\n#### `OutgoingMessage.headersSent`\n\nA boolean. `true` if the response headers have flushed.\n\n#### `OutgoingMessage.setHeader(name, value)`\n\nSet a header to be sent along with the RTSP response body. Throws an\nerror if called after the headers have been flushed.\n\n#### `OutgoingMessage.getHeader(name)`\n\nGet a header value. Case insensitive.\n\n#### `OutgoingMessage.removeHeader(name)`\n\nRemove a header so it is not sent to the client. Case insensitive.\nThrows an error if called after the headers have been flushed.\n\n### `Request`\n\nA writable stream of type `OutgoingMessage` representing an outgoing\nRTSP request. Generated by `encoder.request()`.\n\n### `Response`\n\nA writable stream of type `OutgoingMessage` representing an outgoing\nRTSP response. Generated by `encoder.response()`.\n\n#### `Response.statusCode`\n\nThe status code used in the response. Defaults to `200`. For alist of\nvalid status codes see the `rtspStream.STATUS_CODES` object.\n\n#### `Response.writeHead([statusCode[, statusMessage][, headers]])`\n\nForce writing of the RTSP response headers to the client. Will be called\nautomatically on the first to call to either `response.write()` or\n`response.end()`.\n\nThrows an error if called after the headers have been flushed.\n\nArguments:\n\n- `statusCode` - Set a custom status code (overrides the\n  `response.statusCode` property)\n- `statusMessage` - Set a custom status message related to the status\n  code (e.g. the default status message for the status code `200` is\n  `OK`)\n- `headers` - A key/value headers object used to set extra headers to be\n  sent along with the RTSP response. This will augment the headers\n  already set using the `response.setHeader()` function\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson%2Frtsp-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatson%2Frtsp-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatson%2Frtsp-stream/lists"}