Skip to content

Commit

Permalink
do not patch puppeteer but, export functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelScheit committed Feb 18, 2021
1 parent 9777246 commit f26fe83
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 98 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@ This will patch the launch method of puppeteer to start with this record extensi

### This will only work in headful mode

The method `page.getStream(options)` takes the following options:
The method `page.getStream(options)` takes the following options

```ts
{
audio: boolean; // wheter or not to enable audio
video: boolean; // wheter or not to enable video
audio: boolean; // whether or not to enable audio
video: boolean; // whether or not to enable video
mimeType?: string; // optional mime type of the stream, e.g. "audio/webm" or "video/webm"
audioBitsPerSecond?: number; // The chosen bitrate for the audio component of the media.
videoBitsPerSecond?: number; // The chosen bitrate for the video component of the media.
bitsPerSecond?: number; // The chosen bitrate for the audio and video components of the media. This can be specified instead of the above two properties. If this is specified along with one or the other of the above properties, this will be used for the one that isn't specified.
frameSize?: number = 20; // The number of milliseconds to record into each packet.
}
```

and returns a `Promise<`[`Readable`](/dist/PuppeteerStream.d.ts#L4)`>`

For a detailed documentation of the options have a look at the [HTML5 MediaRecorder Options](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder)

## Example

### [Save Stream to File:](/examples/example.js)
Expand Down
6 changes: 4 additions & 2 deletions dist/PuppeteerStream.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="node" />
import { Page } from "puppeteer/lib/cjs/puppeteer/common/Page";
import puppeteer, { LaunchOptions, Page, BrowserOptions, ChromeArgOptions } from "puppeteer";
import { Readable, ReadableOptions } from "stream";
export declare class Stream extends Readable {
private page;
Expand All @@ -13,7 +13,8 @@ declare module "puppeteer" {
getStream(opts: getStreamOptions): Promise<Stream>;
}
}
export declare type BrowserMimeType = "audio/webm" | "audio/webm;codecs=opus" | "audio/opus" | "audio/aac" | "audio/ogg" | "audio/mp3" | "audio/pcm" | "audio/wav" | "audio/vorbis" | "video/webm" | "video/mp4" | "image/gif";
export declare function launch(opts: LaunchOptions & BrowserOptions & ChromeArgOptions): Promise<puppeteer.Browser>;
export declare type BrowserMimeType = "audio/webm" | "audio/webm;codecs=opus" | "audio/opus" | "audio/aac" | "audio/ogg" | "audio/mp3" | "audio/pcm" | "audio/wav" | "audio/vorbis" | "video/webm" | "video/mp4";
export interface getStreamOptions {
audio: boolean;
video: boolean;
Expand All @@ -23,3 +24,4 @@ export interface getStreamOptions {
bitsPerSecond?: number;
frameSize?: number;
}
export declare function getStream(page: Page, opts: getStreamOptions): Promise<Stream>;
42 changes: 15 additions & 27 deletions dist/PuppeteerStream.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions dist/src/PuppeteerStream.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// <reference types="node" />
import { Page } from "puppeteer/lib/cjs/puppeteer/common/Page";
import { Readable, ReadableOptions } from "stream";
export declare class Stream extends Readable {
private page;
constructor(page: Page, options?: ReadableOptions);
_read(): void;
destroy(): Promise<void>;
}
declare module "puppeteer" {
interface Page {
index: number;
getStream(opts: getStreamOptions): Promise<Stream>;
}
}
export declare type BrowserMimeType = "audio/webm" | "audio/webm;codecs=opus" | "audio/opus" | "audio/aac" | "audio/ogg" | "audio/mp3" | "audio/pcm" | "audio/wav" | "audio/vorbis" | "video/webm" | "video/mp4" | "image/gif";
export interface getStreamOptions {
audio: boolean;
video: boolean;
mimeType?: BrowserMimeType;
audioBitsPerSecond?: number;
videoBitsPerSecond?: number;
bitsPerSecond?: number;
frameSize?: number;
}
Loading

0 comments on commit f26fe83

Please sign in to comment.