I'm working with OpenTok, trying to publish an app where a person shows a room and some clients can see, in order to buy it or not.
When using the example code in my localhost (and also in Firefox and nasty iExplorer) everything works smooth, but when I do it in Chrome i get this error in my JS Console:
OT.Publisher.onStreamAvailableError Permission Denied
I dont remember never saying "no" to any pop up that asked me permition to share my cam, so is not like "Chrome will remember my last choise".
Any help?
This is the code that I'm executing:
<?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>
When I check the JS Console, I get this warning:
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.
An also this Error:
OT.Publisher.onStreamAvailableError Permission Denied
This is our development server, so is not https.
EDIT:
After checking the OpenTok JS that I have to load at the beging, I realice this:
// 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');
So, It won't ask me if I'm using http. There's a way to workaround this? Overwrite this behavior?