I
I
Ivan2020-01-05 19:58:02
JavaScript
Ivan, 2020-01-05 19:58:02

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

1 answer(s)
A
Andrew, 2020-01-05
@skapunker

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

jsx
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;

UPD:
Here is a quick start: https://vk.com/@vkappsdev-quick-start
And here is the roadmap: https://vk.com/dev/roadmap (they disabled the JavaScript SDK for new applications), so use VK Connect .
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.
5e1696564817d193902222.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question