mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Squash: Fix bugs
This commit is contained in:
parent
5c1556ac74
commit
c2b07ad943
6 changed files with 71 additions and 10 deletions
|
@ -7,6 +7,14 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
function SrsError(name, message) {
|
||||
this.name = name;
|
||||
this.message = message;
|
||||
this.stack = (new Error()).stack;
|
||||
}
|
||||
SrsError.prototype = Object.create(Error.prototype);
|
||||
SrsError.prototype.constructor = SrsError;
|
||||
|
||||
// Depends on adapter-7.4.0.min.js from https://github.com/webrtc/adapter
|
||||
// Async-awat-prmise based SRS RTC Publisher.
|
||||
function SrsRtcPublisherAsync() {
|
||||
|
@ -48,7 +56,7 @@ function SrsRtcPublisherAsync() {
|
|||
self.pc.addTransceiver("video", {direction: "sendonly"});
|
||||
|
||||
if (!navigator.mediaDevices && window.location.protocol === 'http:' && window.location.hostname !== 'localhost') {
|
||||
throw new Error(`Please use HTTPS or localhost to publish, read https://github.com/ossrs/srs/issues/2762#issuecomment-983147576`);
|
||||
throw new SrsError('HttpsRequiredError', `Please use HTTPS or localhost to publish, read https://github.com/ossrs/srs/issues/2762#issuecomment-983147576`);
|
||||
}
|
||||
var stream = await navigator.mediaDevices.getUserMedia(self.constraints);
|
||||
|
||||
|
|
|
@ -99,6 +99,25 @@ $(function(){
|
|||
$('#sessionid').html(session.sessionid);
|
||||
$('#simulator-drop').attr('href', session.simulator + '?drop=1&username=' + session.sessionid);
|
||||
}).catch(function (reason) {
|
||||
// Throw by sdk.
|
||||
if (reason instanceof SrsError) {
|
||||
if (reason.name === 'HttpsRequiredError') {
|
||||
alert(`WebRTC推流必须是HTTPS或者localhost:${reason.name} ${reason.message}`);
|
||||
} else {
|
||||
alert(`${reason.name} ${reason.message}`);
|
||||
}
|
||||
}
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#exceptions
|
||||
if (reason instanceof DOMException) {
|
||||
if (reason.name === 'NotFoundError') {
|
||||
alert(`找不到麦克风和摄像头设备:getUserMedia ${reason.name} ${reason.message}`);
|
||||
} else if (reason.name === 'NotAllowedError') {
|
||||
alert(`你禁止了网页访问摄像头和麦克风:getUserMedia ${reason.name} ${reason.message}`);
|
||||
} else if (['AbortError', 'NotAllowedError', 'NotFoundError', 'NotReadableError', 'OverconstrainedError', 'SecurityError', 'TypeError'].includes(reason.name)) {
|
||||
alert(`getUserMedia ${reason.name} ${reason.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
sdk.close();
|
||||
$('#rtc_media_player').hide();
|
||||
console.error(reason);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue