mirror of https://github.com/jitsi/jitsi-meet
parent
8948c837d3
commit
c7b0028652
@ -1,18 +0,0 @@ |
||||
/** |
||||
* Action to remove known DesktopCapturerSources. |
||||
* |
||||
* { |
||||
* type: RESET_DESKTOP_SOURCES, |
||||
* } |
||||
*/ |
||||
export const RESET_DESKTOP_SOURCES = Symbol('RESET_DESKTOP_SOURCES'); |
||||
|
||||
/** |
||||
* Action to replace stored DesktopCapturerSources with new sources. |
||||
* |
||||
* { |
||||
* type: UPDATE_DESKTOP_SOURCES, |
||||
* sources: {Array} |
||||
* } |
||||
*/ |
||||
export const UPDATE_DESKTOP_SOURCES = Symbol('UPDATE_DESKTOP_SOURCES'); |
@ -0,0 +1,73 @@ |
||||
|
||||
const logger = require('jitsi-meet-logger').getLogger(__filename); |
||||
|
||||
/** |
||||
* Begins a request to get available DesktopCapturerSources. |
||||
* |
||||
* @param {Array} types - An array with DesktopCapturerSource type strings. |
||||
* @param {Object} options - Additional configuration for getting a list of |
||||
* sources. |
||||
* @param {Object} options.thumbnailSize - The desired height and width of the |
||||
* return native image object used for the preview image of the source. |
||||
* @returns {Function} |
||||
*/ |
||||
export function obtainDesktopSources(types, options = {}) { |
||||
const capturerOptions = { |
||||
types |
||||
}; |
||||
|
||||
if (options.thumbnailSize) { |
||||
capturerOptions.thumbnailSize = options.thumbnailSize; |
||||
} |
||||
|
||||
return new Promise((resolve, reject) => { |
||||
const { JitsiMeetElectron } = window; |
||||
|
||||
if (JitsiMeetElectron && JitsiMeetElectron.obtainDesktopStreams) { |
||||
JitsiMeetElectron.obtainDesktopStreams( |
||||
sources => resolve(_seperateSourcesByType(sources)), |
||||
error => { |
||||
logger.error( |
||||
`Error while obtaining desktop sources: ${error}`); |
||||
reject(error); |
||||
}, |
||||
capturerOptions |
||||
); |
||||
} else { |
||||
const reason = 'Called JitsiMeetElectron.obtainDesktopStreams' |
||||
+ ' but it is not defined'; |
||||
|
||||
logger.error(reason); |
||||
|
||||
return Promise.reject(new Error(reason)); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Converts an array of DesktopCapturerSources to an object with types for keys |
||||
* and values being an array with sources of the key's type. |
||||
* |
||||
* @param {Array} sources - DesktopCapturerSources. |
||||
* @private |
||||
* @returns {Object} An object with the sources split into seperate arrays based |
||||
* on source type. |
||||
*/ |
||||
function _seperateSourcesByType(sources = []) { |
||||
const sourcesByType = { |
||||
screen: [], |
||||
window: [] |
||||
}; |
||||
|
||||
sources.forEach(source => { |
||||
const idParts = source.id.split(':'); |
||||
const type = idParts[0]; |
||||
|
||||
if (sourcesByType[type]) { |
||||
sourcesByType[type].push(source); |
||||
} |
||||
}); |
||||
|
||||
return sourcesByType; |
||||
} |
@ -1,62 +0,0 @@ |
||||
import { ReducerRegistry } from '../base/redux'; |
||||
|
||||
import { |
||||
RESET_DESKTOP_SOURCES, |
||||
UPDATE_DESKTOP_SOURCES |
||||
} from './actionTypes'; |
||||
|
||||
const DEFAULT_STATE = { |
||||
screen: [], |
||||
window: [] |
||||
}; |
||||
|
||||
/** |
||||
* Listen for actions that mutate the known available DesktopCapturerSources. |
||||
* |
||||
* @param {Object[]} state - Current state. |
||||
* @param {Object} action - Action object. |
||||
* @param {string} action.type - Type of action. |
||||
* @param {Array} action.sources - DesktopCapturerSources. |
||||
* @returns {Object} |
||||
*/ |
||||
ReducerRegistry.register( |
||||
'features/desktop-picker', |
||||
(state = DEFAULT_STATE, action) => { |
||||
switch (action.type) { |
||||
case RESET_DESKTOP_SOURCES: |
||||
return { ...DEFAULT_STATE }; |
||||
|
||||
case UPDATE_DESKTOP_SOURCES: |
||||
return _seperateSourcesByType(action.sources); |
||||
|
||||
default: |
||||
return state; |
||||
} |
||||
}); |
||||
|
||||
/** |
||||
* Converts an array of DesktopCapturerSources to an object with types for keys |
||||
* and values being an array with sources of the key's type. |
||||
* |
||||
* @param {Array} sources - DesktopCapturerSources. |
||||
* @private |
||||
* @returns {Object} An object with the sources split into seperate arrays based |
||||
* on source type. |
||||
*/ |
||||
function _seperateSourcesByType(sources = []) { |
||||
const sourcesByType = { |
||||
screen: [], |
||||
window: [] |
||||
}; |
||||
|
||||
sources.forEach(source => { |
||||
const idParts = source.id.split(':'); |
||||
const type = idParts[0]; |
||||
|
||||
if (sourcesByType[type]) { |
||||
sourcesByType[type].push(source); |
||||
} |
||||
}); |
||||
|
||||
return sourcesByType; |
||||
} |
Loading…
Reference in new issue