即时通讯试图共享我的屏幕并记录它,但问题是当我选择流的源时,它没有开始流式传输,它仅显示具有共享的屏幕和窗口选项的窗口,但是选择一个后,我检查了获取ChromeMediaSource和ChromeMediaSourceID,但是正如我所说,不会显示共享对话框,因此我无法记录任何内容。

这是我发现未登录到控制台的调试错误:

" at chrome-extension://mnoggiilghljimfhpghalhngdciecafi/background.js:16:31"


在后台文件的“ chrome.desktopCapture.chooseDesktopMedia”中

这是我的背景文件

background.js

chrome.runtime.onConnect.addListener( function( port ){
    // listen for messages from the port

    port.onMessage.addListener( function( message ){
        // send back a "pending" answer on the port
        port.postMessage( {
            "answer": 1,
            "state": "pending",
            "requestId": message.requestId
        } );
        chrome.desktopCapture.chooseDesktopMedia(["screen", "window"], port.sender.tab, function( id ){


            var response = {
                "answer": 1,
                "state": "completed",
                "requestId": message.requestId,
                "streamId": id || undefined
            };

            // send back a "completed" answer on the port
            port.postMessage( response );
        } );
    } );
} );


这是使用扩展名加载到网站上的文件

bridge.js

// open a port to communicate with background
var port = chrome.runtime.connect();

// create node
var node = document.createElement( 'div' );

// listen for messages from webpage and forward them to the background, through the previously opened port
window.addEventListener( 'message', function ( event ){
    if ( event.source != window || !event.data ){
        return;
    }
    // prevent to return answer to the background
    if( event.data.answer ){
        return;
    }

    port.postMessage( event.data );

} );

// listen for messages from background and forward them to the webpage
port.onMessage.addListener( function( data ){
    window.postMessage( data, '*' );
} );

// insert tag into parent page
node.id = 'extension-screensharing-installed';
document.body.appendChild( node );


manifest.js

{
  "name": "extension name",
  "description": "This extension allows you to share your screen",
  "version": "0.1",
  "manifest_version": 2,
  "minimum_chrome_version": "34",
  "icons": {
    "16": "img16.png",
    "48": "img48.png",
    "128": "img128.png"
  },
  "background": {
    "scripts": ["background.js"]
  },
  "content_scripts": [ {
    "js": [ "bridge.js" ],
    "matches": [
      "https://*/tester"
      ]
  } ],
  "permissions": [
    "desktopCapture",
    "https://*/tester"
  ]
}


我的代码可能出问题了吗?
我不完全了解通过调试发现的错误

谢谢!

编辑:添加manifest.json文件!

最佳答案

Developing a Chrome screen-sharing extension包括有关开发扩展的说明和示例代码,其中输入了apiKeysessionIdtoken的值,并且还使用了OT.registerScreenSharingExtension()方法来注册屏幕共享扩展。

    // API key and generate a test session ID and token:
    var apiKey    = "<YOUR_API_KEY>";
    var sessionId = "<YOUR_SESSION_ID>";
    var token     = "<YOUR_TOKEN>";

    var session = OT.initSession(apiKey, sessionId);

    session.connect(token, function(error) {
      var publisher = OT.initPublisher('camera');
      session.publish(publisher, function() {
        screenshare();
      });
    });

    session.on('streamCreated', function(event) {
      session.subscribe(event.stream);
    });

    OT.registerScreenSharingExtension('chrome', '<YOUR_CHROME_EXTENSION_ID>', 2);


对于录音部分,您可以在Screensharing with WebRTC中检查他们的操作方式。希望能帮助到你!

关于javascript - 无法与我的Chrome扩展程序共享屏幕,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36545465/

10-16 23:28