Skip to content

Commit

Permalink
Merge pull request #257 from AgoraIO/dev-xuch
Browse files Browse the repository at this point in the history
NEW: request permission before getDevices
  • Loading branch information
plutoless authored Jan 30, 2021
2 parents fb0947f + 125e05e commit 7f1060c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
13 changes: 13 additions & 0 deletions One-to-One-Video/Agora-Web-Tutorial-1to1-Webpack/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ export function removeView (id) {
}
}

export function requestPermission(next) {
const tempAudioVideoStream = AgoraRTC.createStream({ audio: true, video: true })
const callback = function (hasPermission) {
tempAudioVideoStream.close()
next(hasPermission)
}
tempAudioVideoStream.init(function () {
callback(true)
}, function () {
callback(false)
})
}

export function getDevices (next) {
AgoraRTC.getDevices(function (items) {
items.filter(function (item) {
Expand Down
47 changes: 26 additions & 21 deletions One-to-One-Video/Agora-Web-Tutorial-1to1-Webpack/src/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import RTCClient from './rtc-client'
import {getDevices, Toast, serializeFormData, validator, resolutions} from './common'
import {requestPermission, getDevices, Toast, serializeFormData, validator, resolutions} from './common'
import './assets/style.css'
import * as M from 'materialize-css'
// import {setFormData, parseFromSearch} from './searchParam';

$(() => {
getDevices(function (devices) {
devices.audios.forEach(function (audio) {
$('<option/>', {
value: audio.value,
text: audio.name,
}).appendTo('#microphoneId')
})
devices.videos.forEach(function (video) {
$('<option/>', {
value: video.value,
text: video.name,
}).appendTo('#cameraId')
})
resolutions.forEach(function (resolution) {
$('<option/>', {
value: resolution.value,
text: resolution.name
}).appendTo('#cameraResolution')
$(() => {
requestPermission(function (hasPermission) {
if (!hasPermission) {
Toast.error('no camera or microphone permission!')
}
getDevices(function (devices) {
devices.audios.forEach(function (audio) {
$('<option/>', {
value: audio.value,
text: audio.name,
}).appendTo('#microphoneId')
})
devices.videos.forEach(function (video) {
$('<option/>', {
value: video.value,
text: video.name,
}).appendTo('#cameraId')
})
resolutions.forEach(function (resolution) {
$('<option/>', {
value: resolution.value,
text: resolution.name
}).appendTo('#cameraResolution')
})
M.AutoInit()
})
M.AutoInit()
})

const fields = ['appID', 'channel']
Expand Down

0 comments on commit 7f1060c

Please sign in to comment.