import React from 'react'; import {ReactMic} from 'react-mic'; import { SessionIconButton, SessionIconSize, SessionIconType } from '../icon'; import { SessionButton, SessionButtonType, SessionButtonColor } from '../SessionButton'; interface Props { onStoppedRecording: any; } interface State { recordDuration: number; isRecording: boolean; isPaused: boolean; actionHover: boolean; } export class SessionRecording extends React.Component { constructor(props: any) { super(props); this.state = { recordDuration: 0, isRecording: true, isPaused: false, actionHover: false, }; this.handleHoverActions = this.handleHoverActions.bind(this); this.handleUnhoverActions = this.handleUnhoverActions.bind(this); this.onPlayRecording = this.onPlayRecording.bind(this); this.onStopRecording = this.onStopRecording.bind(this); this.onSendVoiceMessage = this.onSendVoiceMessage.bind(this); this.onDeleteVoiceMessage = this.onDeleteVoiceMessage.bind(this); } public componentWillReceiveProps(){ console.log(`[vince][mic] Here are my composition props: `, this.props); console.log(`[vince][mic] Permissions: `, navigator.getUserMedia({ audio: true }, () => null, error => alert(error))); } render() { const actionPause = (this.state.actionHover && this.state.isRecording); const actionPlay = (!this.state.isRecording || this.state.isPaused); const actionDefault = !actionPause && !actionPlay; return (
{actionPause && ( )} {actionPlay && ( )} {actionDefault && ( )}
null} onData= {(data: any) => console.log(`[vince][mic] Data:`, data)} strokeColor={'#00F480'} backgroundColor={'blue'} />
); } private handleHoverActions() { if ((this.state.isRecording) && !this.state.actionHover) { this.setState({ actionHover: true, }); } } private handleUnhoverActions() { if (this.state.isRecording && this.state.actionHover) { this.setState({ actionHover: false, }); } } private onStopRecording() { console.log(`[vince][mic] Stopped recording`); this.setState({ isRecording: false, isPaused: true, }); } private onPlayRecording() { console.log(`[vince][mic] Playing recording`); this.setState({ isRecording: false, isPaused: false, }); } private onDeleteVoiceMessage() { this.onStopRecording(); this.props.onStoppedRecording(); } private onSendVoiceMessage() { console.log(`[vince][mic] Sending voice message`); } }