Permission Denied during session.publish()

Ask questions about the JavaScript API here

Permission Denied during session.publish()

Postby mwang » Sat Dec 01, 2012 3:05 am

I am trying out the WebRTC JavaScript API, but failed in pulling out the camera.

index.html
Code: Select all
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <title>OpenTok Getting Started</title>
  <script src="http://static.opentok.com/webrtc/v2.0/js/TB.min.js"  type="text/javascript"></script>

  <script type="text/javascript">
    var apiKey = '******';
    var token = '*****';
    var sessionId = '*****';

   var session = TB.initSession(sessionId);
   session.addEventListener('sessionConnected', sessionConnectedHandler);
   session.addEventListener('streamCreated', streamCreatedHandler);
   session.connect(apiKey, token);

   function sessionConnectedHandler(event) {
       subscribeToStreams(event.streams);
       session.publish();
   }

   function streamCreatedHandler(event) {
       subscribeToStreams(event.streams);
   }

   function subscribeToStreams(streams) {
       for (i = 0; i < streams.length; i++) {
           var stream = streams[i];
           if (stream.connection.connectionId != session.connection.connectionId) {
               session.subscribe(stream);
           }
       }
   }

  </script>
</head>

<body>
</body>
</html>


I also tried
Code: Select all
      function sessionConnectedHandler(event) {
        subscribeToStreams(event.streams);
        publisher = TB.initPublisher(apiKey, 'myPublisherDiv');
        session.publish(publisher);
     }
 ...
 
  <body>
    <div id="myPublisherDiv"></div>
  </body>

...


I tested locally at "file:///home/********/Downloads/index.html" in Chrome v23 at different platform, OSX, Win7, Ubuntu.

All I got on the web page is a black rectangular on the left up corner.

Error message from Console:

OT.rtc.Publisher.onStreamAvailableError Permission Denied
Uncaught ReferenceError: reason is not defined
(Please refer to attachment for detailed console screenshot)

I run the diagnose scan tool provided in the forum, the only minor issue pops out is: Port 443 should be open, Failed to connect
I am so confused, since I can successfully run the tutorial at http://tokbox.com/opentok/api/tools/js_webrtc/tutorials/helloworld.html.

----------------------------------------------------------------
I also tried the flash javaScript API, by utilizing the example source code, the Chrome simply keeps gave Connection Timeout alert message.
Was this post helpful? (0)
Attachments
console_output.png
mwang
 
Posts: 2
Joined: Thu Nov 29, 2012 7:44 pm
Thumbs Up: 0

Re: Permission Denied during session.publish()

Postby mwang » Sat Dec 01, 2012 2:49 pm

It actually works after I put it onto web server.
Can we actually test locally? If so, please advise how. Thanks in advance.
Was this post helpful? (0)
mwang
 
Posts: 2
Joined: Thu Nov 29, 2012 7:44 pm
Thumbs Up: 0

Re: Permission Denied during session.publish()

Postby ankur » Mon Dec 03, 2012 5:54 am

Hey there,

This is a side effect of the security policy of the browser. The getUserMedia() call will fail when called from a page that is loaded on a file:// URI scheme.

I do think that our error message could be more descriptive though. Actually our next release will prompt you specifically that the page has been loaded with a local URI scheme, so the fix for this is already done.

As far as testing locally, it's generally better practice (not just for this reason alone) to run a local web server (Apache, nginx, Thin, etc) than to develop while loading from the file system. If you need any help with this, let us know which backend language/framework you wish to use and we can help.

--Ankur
Was this post helpful? (0)
ankur
 
Posts: 356
Joined: Thu Jun 02, 2011 12:37 am
Thumbs Up: 12


Return to JavaScript



Who is online

Users browsing this forum: Alexa [Bot] and 2 guests

cron