2016-01-11 22 views

回答

2

是的,这是可能的!
但据我所知仅适用于Firefox和Chrome(我使用Chrome)。感谢Screen Capturing和WebRTC。 More info about WebRTC

我使用了一个名为RTCMultiConnection的库,它非常易于使用,但是您应该可以在不使用任何库的情况下执行此操作。

这里,只是给你一个起点:

// 1. Create the connection Objekt 
var connection = new RTCMultiConnection(); 

// 2. Activate screen, which is the whole monitor, not only the browser window! 
connection.session = { 
    screen: true, 
    data: false, 
    oneway: true 
}; 

// 3. Create the callback for the stream 
connection.onstream = function(event) { 
    // Make something with the event 
    // event.stream contains the stream, event.mediaElement the media 
    // I used event.mediaElement as parameter to draw the frage into an canvas; via context2d.drawImage(event.mediaElement, ...) 
    // Then I create an base64 String via canvas.toDataURL("image/png") and 
    // Don't forget to stop the stream if you just want to have one single image 
}; 

// 4. Start Desktop Sharing 
connection.open({ 
    // you could register a onMediaCaptured callback here 
});