proyecto26 / record-audio-button-enterprise

๐Ÿ”ด A Web Component for Recording Audio with a swipe gesture inspired by WhatsApp (Enterprise) ๐Ÿ’ผ
https://proyecto26.com/record-audio-button-enterprise
4 stars 0 forks source link
angular angular2 angularjs capacitor cordova ionic ionic-framework react reactjs stencil stencil-components stencil-js stenciljs stenciljs-components vanilla-javascript vanilla-js vue vuejs webcomponent webcomponents

Built With Stencil

Record Audio Button (Enterprise)

Web Component built with Stencil.js for Recording Audio from Web using Web RTC and Mobile using native plugins, with a swipe gesture using Ionic Animations inspired by WhatsApp:

<record-audio-button autoplay enable-recording></record-audio-button>

Demo ๐ŸŽฎ

Do you want to see this web component in action? Check our demo projects for Angular, React, Vue, VanillaJS, etc, yay! ๐ŸŽ‰

Record Audio Button

Usage ๐ŸŽ‰

<record-audio-button
  color="light"
  activated="false"
  disabled="false"
  show
  translucent
  type="submit"
  size="large"
  max-threshold="10"
  button-style=""
  button-class=""
  icon-name="mic"
  icon-size="large"
  icon-style=""
  icon-class=""
  icon-aria-label=""
  icon-ios=""
  icon-md=""
  icon-src="https://github.com/proyecto26/record-audio-button-enterprise/raw/master/"
  scale-x="1.2"
  scale-y="1.2"
  width="55"
  height="55"
  max-width="90"
  duration="200"
  enable-logs
  enable-recording
  autoPlay
  mime-type="audio/webm"
  time-slice="0"
  audio-bits-per-second="0"
  sample-rate="0"
  desired-samp-rate="0"
  buffer-size="0"
  number-of-audio-channels="0"
>
</record-audio-button>

Getting Started ๐Ÿ“–

Packages

Project Package
Core @proyecto26/record-audio-button
React @proyecto26/record-audio-button-react

Node Modules

In a stencil-starter app

Framework integrations ๐Ÿ‘จโ€๐Ÿ’ป

Angular

Using record-audio-button component within an Angular project:

Including the Custom Elements Schema

Including the CUSTOM_ELEMENTS_SCHEMA in the module allows the use of Web Components in the HTML files. Here is an example of adding it to AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule {}

The CUSTOM_ELEMENTS_SCHEMA needs to be included in any module that uses record-audio-button.

Calling defineCustomElements

record-audio-button component includes a function used to load itself in the application window object. That function is called defineCustomElements() and needs to be executed once during the bootstrapping of your application. One convenient place to add it is in the main.ts file as follows:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { defineCustomElements as defineRecordAudioButton } from '@proyecto26/record-audio-button/loader';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));
defineRecordAudioButton(window);

from stencil documentation

React

When using a wrapper component, It's not necessary to access the reference directly to attach events, etc. More details here.

import React from 'react';
import {
  RecordAudioButton
} from '@proyecto26/record-audio-button';

const App = () => {
  return (
    <RecordAudioButton
      color="light"
      scaleX={1.3}
      scaleY={1.3}
      maxWidth={100}
      duration={200}
      autoPlay={false}
      enableLogs
      enableRecording={true}
    />
  );
};
export default App;

Other option is using the web component directly:

import React from 'react'
import ReactDOM from 'react-dom'
import { defineCustomElements as defineRecordAudioButton } from '@proyecto26/record-audio-button/loader'
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));

defineRecordAudioButton(window);

from stencil documentation

Vue

In order to use the record-audio-button Web Component inside of a Vue application, it should be modified to define the custom elements and to inform the Vue compiler which elements to ignore during compilation. This can all be done within the main.js file as follows:

import Vue from 'vue';
import { defineCustomElements as defineRecordAudioButton } from '@proyecto26/record-audio-button/loader'

import App from './App.vue';

Vue.config.productionTip = false;
Vue.config.ignoredElements = [/ion-\w*/, /record-\w*/];

// Bind the custom element to the window object
defineRecordAudioButton(window);

new Vue({
  render: h => h(App)
}).$mount('#app');

from stencil documentation

Credits ๐Ÿ‘

Happy coding ๐Ÿ’ฏ

Made with โค๏ธ