Refine: make desktop-capturer as a renderer module.
This commit is contained in:
parent
48fbd47416
commit
1e69ef79de
12 changed files with 237 additions and 74 deletions
42
atom/browser/lib/desktop-capturer.coffee
Normal file
42
atom/browser/lib/desktop-capturer.coffee
Normal file
|
@ -0,0 +1,42 @@
|
|||
ipc = require 'ipc'
|
||||
BrowserWindow = require 'browser-window'
|
||||
EventEmitter = require('events').EventEmitter
|
||||
|
||||
# The browser module manages all desktop-capturer moduels in renderer process.
|
||||
desktopCapturer = process.atomBinding('desktop_capturer').desktopCapturer
|
||||
desktopCapturer.__proto__ = EventEmitter.prototype
|
||||
|
||||
getWebContentsFromId = (id) ->
|
||||
windows = BrowserWindow.getAllWindows()
|
||||
return window.webContents for window in windows when window.webContents?.getId() == id
|
||||
|
||||
# The set for tracking id of webContents.
|
||||
webContentsIds = new Set
|
||||
|
||||
stopDesktopCapture = (id) ->
|
||||
webContentsIds.delete id
|
||||
if webContentsIds.size is 0
|
||||
desktopCapturer.stopUpdating()
|
||||
|
||||
ipc.on 'ATOM_BROWSER_DESKTOP_CAPTURER_REQUIRED', (event) ->
|
||||
id = event.sender.getId()
|
||||
# Remove the tracked webContents when it is destroyed.
|
||||
getWebContentsFromId(id).on 'destroyed', ()->
|
||||
stopDesktopCapture id
|
||||
event.returnValue = 'done'
|
||||
|
||||
# Handle `desktopCapturer.startUpdating` API.
|
||||
ipc.on 'ATOM_BROWSER_DESKTOP_CAPTURER_START_UPDATING', (event, args) ->
|
||||
id = event.sender.getId()
|
||||
webContentsIds.add id
|
||||
desktopCapturer.startUpdating args
|
||||
|
||||
# Handle `desktopCapturer.stopUpdating` API.
|
||||
ipc.on 'ATOM_BROWSER_DESKTOP_CAPTURER_STOP_UPDATING', (event) ->
|
||||
stopDesktopCapture event.sender.getId()
|
||||
|
||||
for event_name in ['source-added', 'source-removed', 'source-name-changed', "source-thumbnail-changed"]
|
||||
do (event_name) ->
|
||||
desktopCapturer.on event_name, (event, source) ->
|
||||
webContentsIds.forEach (id) ->
|
||||
getWebContentsFromId(id).send event_name, { id: source.id, name: source.name, dataUrl: source.thumbnail.toDataUrl() }
|
|
@ -92,6 +92,9 @@ app.setAppPath packagePath
|
|||
# Load the chrome extension support.
|
||||
require './chrome-extension'
|
||||
|
||||
# Load internal desktop-capturer module.
|
||||
require './desktop-capturer'
|
||||
|
||||
# Set main startup script of the app.
|
||||
mainStartupScript = packageJson.main or 'index.js'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue