1.0.16 • Published 2 months ago

@hilma/web-recorder v1.0.16

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

Web Recorder Module is for recording users.

This package uses React and Fileshandler modules, and saves the recording as an audio file.

Installation

In the client folder, run:

$ npm i @hilma/web-recorder

usage:

First you have to create a FilesUploader instance (For more details check the Fileshandler docs).

The next step is to render the Recorder component .The Recorder component takes the following props:

PropTypeDescriptionRequired
filesUploaderFilesUploaderFilesUploader instancetrue
startRecordingBtnJSX.ElementThe button (or any other jsx element) that starts the recording.(in case that you won't pass stopRecordingBtn this element will also stop the recording).true
stopRecordingBtnJSX.ElementThe button (or any other jsx element) that stops the recording.false
onEndedfunctionFunction that gets called when the recording has ended, gets same parameter as the onChange function in Fileshandler . (with a temporary link for the file, a file identifier and so on)false
onErrorfunctionIn case of error this function gets called.false
disableStopwatchbooleanIf true , the stopwatch won’t be shownfalse
stopwatchClassnamestringclassName to style the stopwatchfalse
recorderClassnamestringclassName to style the componentfalse

Example:

import React, { FC, useState } from 'react';

import { useFiles } from '@hilma/fileshandler-client';
import { Recorder } from '@hilma/web-recorder';

const RecorderExample: FC = () => {

    const filesUploader = useFiles();
    const [link, setLink] = useState<null | string>(null);
    const [errorMessage, setErrorMessage] = useState<null | string>(null);

    const handelError = (error: any) => {
        console.log('error: ', error);
        setErrorMessage('לא הצלחנו להקליט אותך, נסה שנית');
    }

    return (
        <div>
            <Recorder 
                filesUploader={filesUploader}
                onEnded={value => setLink(value.link)}
                onError={handelError}
                startRecordingBtn={<button> start </button>}
                stopRecordingBtn={<button> stop </button>}
                stopwatchClassname='stopwatch'
            />

            {link ? <audio src={link} controls /> : null}

            {errorMessage ? <div>{errorMessage}</div> : null}
        </div>
    );
}

export default RecorderExample;

Controlled Recorder:

if you want to control when the user is recorded (not just by pressing the buttons) or get the isRecording value, you can use the ControlledRecorder component.

You need to pass it the Recorder props and also:

PropTypeDescriptionRequired
isRecordingbooleandetermines if the component is recordingtrue
setIsRecordingfunctionchanges the isRecording proptrue

Example

import React, { FC, useState } from 'react';

import { useFiles } from '@hilma/fileshandler-client';
import { ControlledRecorder } from '@hilma/web-recorder';

const ControlledRecorderExample: FC = () => {

    const filesUploader = useFiles();

    const [link, setLink] = useState<null | string>(null);
    const [isRecording, setIsRecording] = useState(false);
    const [errorMessage, setErrorMessage] = useState<null | string>(null);

    const handelError = (error: any) => {
        console.log('error: ', error);
        setErrorMessage('לא הצלחנו להקליט אותך, נסה שנית');
    }

    return (
        <div>
            <ControlledRecorder
                filesUploader={filesUploader}
                onEnded={value => setLink(value.link)}
                onError={handelError}
                startRecordingBtn={<button> start </button>}
                stopRecordingBtn={<button> stop </button>}
                isRecording={isRecording}
                setIsRecording={setIsRecording}
                stopwatchClassname='stopwatch'
            />

            {link ? <audio src={link} controls /> : null}

            {errorMessage ? <div>{errorMessage}</div> : null}
        </div>
    );
}

export default ControlledRecorderExample;

The recording is handled like any other uploaded file in Fileshandler module.

Note:

On Chrome you get webm file type, witch is not supported on Safari (ios). to play the audio on safari you need to convert it to mp3 file using ffmpeg.

1.0.16-beta.0

2 months ago

1.0.16-beta.3

2 months ago

1.0.16-beta.1

2 months ago

1.0.16-beta.2

2 months ago

1.0.16

2 years ago

1.0.15-beta0.6

2 years ago

1.0.15-beta0.5

2 years ago

1.0.15-beta0.4

2 years ago

1.0.15-beta0.3

2 years ago

1.0.15-beta0.2

2 years ago

1.0.15-beta0.1

2 years ago

1.0.14-beta0.1

2 years ago

1.0.14-beta0.2

2 years ago

1.0.13-beta0.1

2 years ago

1.0.15

2 years ago

1.0.13-beta0.2

2 years ago

1.0.14

2 years ago

1.0.12-beta0.4

2 years ago

1.0.12-beta0.3

2 years ago

1.0.13

2 years ago

1.0.12-beta0.2

2 years ago

1.0.12-beta0.1

2 years ago

1.0.12

3 years ago

1.0.10-beta.0

3 years ago

1.0.10-beta.2

3 years ago

1.0.10-beta.1

3 years ago

1.0.10-beta.4

3 years ago

1.0.10-beta.3

3 years ago

1.0.10-beta.6

3 years ago

1.0.10-beta.5

3 years ago

1.0.10-beta.8

3 years ago

1.0.10-beta.7

3 years ago

1.0.10-beta.9

3 years ago

1.0.10-beta.14

3 years ago

1.0.10-beta.12

3 years ago

1.0.10-beta.13

3 years ago

1.0.10-beta.10

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago