2016-01-11 52 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 
});