-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
25 lines (24 loc) · 945 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const sourceId2CoordinatesLib
= require("./build/Release/sourceid-2-coordinates");
/**
* Returns the coordinates of a desktop using the passed desktop sharing source
* id.
*
* @param {string} sourceId - The desktop sharing source id.
* @returns {Object.<string, number>|undefined} - The x and y coordinates of the
* top left corner of the desktop. Currently works only for windows. Returns
* undefined for Mac OS, Linux.
*/
module.exports.sourceId2Coordinates = function(sourceId) {
if(typeof sourceId !== "string" || sourceId === '') {
return undefined;
}
// On windows the source id will have the following format "desktop_id:0".
// we need the "desktop_id" only to get the coordinates.
const idArr = sourceId.split(":");
const id = Number(idArr.length > 1 ? idArr[0] : sourceId);
if(!isNaN(id)) {
return sourceId2CoordinatesLib.sourceId2Coordinates(id);
}
return undefined;
};