Answer the question
In order to leave comments, you need to log in
How to call a request to turn on the camera and microphone in the Vkontakte application?
Hello! Guys, please tell me how to call a request to turn on the camera and microphone in the Vkontakte application?
The application is made for Android and iOS mobile clients. Connected via frame. It is necessary immediately after loading to call requests to turn on the webcam and microphone.
Answer the question
In order to leave comments, you need to log in
There is a method MediaDevices.getUserMedia()
It will work in VK Mini Apps .
I'll even show you a working piece of code, then figure it out yourself
import React from 'react';
import {Div, Group, Panel, View} from '@vkontakte/vkui';
import '@vkontakte/vkui/dist/vkui.css';
class App extends React.Component {
constructor(props) {
super(props);
this.videoRef = React.createRef();
this.handleVideo = this.handleVideo.bind(this);
this.videoError = this.videoError.bind(this);
}
handleVideo(stream) {
this.videoRef.current.srcObject = stream;
}
videoError = (err) => {
alert(err.name)
}
componentDidMount() {
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
if (navigator.getUserMedia) {
let constraints = {
audio: false,
video: {facingMode: 'environment'}
};
navigator.mediaDevices.getUserMedia(constraints)
.then(this.handleVideo)
.catch(this.videoError)
}
}
render() {
return (
<View activePanel="mainPanel" header={false}>
<Panel id="mainPanel">
<Group>
<Div>
<video ref={this.videoRef} style={{width: '100%'}} playsInline autoPlay muted/>
</Div>
</Group>
</Panel>
</View>
);
}
}
export default App;
Community apps are now based on the JavaScript SDK. However, in order to stay on the cutting edge of technology and unify the development of the entire VK ecosystem, we have decided to abandon the JavaScript SDK in favor of VK Connect.
From March 1, applications that are integrated with the platform via the JavaScript SDK will no longer work. Only applications that use VK Connect will be placed in the catalog.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question