我正在使用OpenTok,试图发布一个应用程序,其中一个人显示一个房间,一些客户可以看到,以便购买或不购买。
在我的localhost(以及Firefox和讨厌的iExplorer)中使用示例代码时,一切顺利,但是当我在Chrome中执行此操作时,我在JS控制台中出现此错误:
OT.Publisher.onStreamAvailableError Permission Denied
我不记得从来没有对任何要求我分享我的相机的弹出说“不”,所以不喜欢“Chrome会记住我的最后一次选择”。
任何帮助?
这是我正在执行的代码:
<?php
//Obviously I changed this.
$apiKey = "123456789";
$apiSecret = "VICTORIA's SECRET";
require '../vendor/autoload.php';
use OpenTok\OpenTok;
use OpenTok\MediaMode;
use OpenTok\Session;
use OpenTok\Role;
$opentok = new OpenTok($apiKey,$apiSecret);
$session = $opentok->createSession();
$sessionId = $session->getSessionId();
$data = array(
'role' => Role::PUBLISHER,
'data' =>""
);
$token = $session->generateToken($data);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>OpenTok Hello World</title>
<script src='https://static.opentok.com/v2/js/opentok.min.js'></script>
<!--script src="//static.opentok.com/webrtc/v2.2/js/TB.min.js"></script-->
<script type="text/javascript">
var token = '<?php echo $token; ?>';
var apiKey = '<?php echo $apiKey; ?>';
var sessionId = '<?php echo $sessionId; ?>';
var session = TB.initSession(sessionId);
var publisher = TB.initPublisher(apiKey, 'subscribers');
// Attach event handlers
session.on({
sessionConnected: function(event)
{
session.publish(publisher);
},
streamCreated: function(event)
{
var subContainer = document.createElement('div');
subContainer.id = 'stream-' + event.stream.streamId;
document.getElementById('subscribers').appendChild(subContainer);
session.subscribe(event.stream, subContainer);
}
});
session.connect(apiKey, token);
</script>
</head>
<body>
<h2>Hello, Universe!</h2>
<div id="publisher"></div>
<div id="subscribers"></div>
</body>
</html>
当我检查JS控制台时,我收到此警告:
getUserMedia() no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.
也是这个错误:
OT.Publisher.onStreamAvailableError Permission Denied
这是我们的开发服务器,因此不是https。
编辑:
在检查了我必须在beging上加载的OpenTok JS之后,我实现了这个:
// The user has clicked the 'deny' button the the allow access dialog
// (or it's set to always deny)
var onAccessDenied = function(error) {
if (_isScreenSharing) {
if (global.location.protocol !== 'https:') {
/**
* in http:// the browser will deny permission without asking the
* user. There is also no way to tell if it was denied by the
* user, or prevented from the browser.
*/
error.message += ' Note: https:// is required for screen sharing.';
}
}
logging.error('OT.Publisher.onStreamAvailableError Permission Denied');
所以,它不会问我是否使用http。有办法解决这个问题吗?覆盖这种行为?