Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which kind of format must be? #348

Open
AmadeusDeadDmytro opened this issue Mar 26, 2024 · 2 comments
Open

Which kind of format must be? #348

AmadeusDeadDmytro opened this issue Mar 26, 2024 · 2 comments
Assignees

Comments

@AmadeusDeadDmytro
Copy link

AmadeusDeadDmytro commented Mar 26, 2024

I tring to change value in Screen capture,
Documentation sad about XML string. Can you give me example such XML?

I try this, but no effect, just source crashed

<screen> <item> <type>ScreenCapture2</type> <captureType>window</captureType> <windowTitle>My Application</windowTitle> <windowClass></windowClass> <windowHandle>0</windowHandle> </item> </screen>

@SML-MeSo
Copy link
Collaborator

SML-MeSo commented Apr 1, 2024

Yes, unfortunately, the documentation may have been lacking in that regard. A sample string could be <screen module="\device\harddiskvolume4\users\meso\appdata\local\slack\app-4.37.98\slack.exe" window="general (Channel) - SplitmediaLabs Limited - Slack" class="Chrome_WidgetWin_1" desktop="" hwnd="133558" wclient="1" left="0" top="0" width="0" height="0"> where available screens and their details can be fetched via xjs.System.getAvailableScreens. The said method, getAvailableScreens, however, is currently broken since XBC v.4.5.2307.1301 due to the move from using XSplitScriptPlugin.dll to Xjs.dll

For the latest XBC versions, the following code can be used to fetch for available windows (getWindows) and available monitors (getMonitors) : (Oh, and apologies, as we are about to dig deeper here)

const oldAsyncDllCallback = window.OnDllCallback;
window.OnDllCallback = (funcName, asyncID, result) => { 

  let callback = window.ownDllCallBacks[asyncID];

  if (callback instanceof Function) {
    callback(decodeURIComponent(result));
    delete window.ownDllCallBacks[asyncID];
  }  

  if(typeof oldAsyncDllCallback === 'function') {
    oldAsyncDllCallback(funcName, asyncID, result);
  }
};

const execDll = (funcName, ...args) => {
  let callback = null;
  let ret = false;

  if (args.length > 0) {
    callback = args[args.length - 1];
    if (callback instanceof Function) {
      args.pop();
    } else {
      callback = null;
    }
  }

  if (
    window.external &&
    window.external[funcName] &&
    window.external[funcName] instanceof Function
  ) {
    ret = window.external[funcName](...args);
    ret = ret.replace('async:', '');
  }

  // register callback if present
  if (callback !== null) {
    window.ownDllCallBacks[ret] = callback;
  }
};

const execDllPromise = (funcName, ...args) => {
  return new Promise(resolve => {
    execDll('CallDll', funcName, ...args, resolve);
  });
};

const getMonitors = async (isDetailed = false) => {
  try {
    const monitorsStr = await execDllPromise('XSplit.Monitor.Enum');

    const monitors = monitorsStr.split('|');

    return Promise.all(
      monitors.map(async monitor => {
        const [hwnd, left, top, width, height] = monitor.split(',').map(Number);
        return {
          id: await execDllPromise('XSplit.Monitor.GetId', String(hwnd)),
          hwnd,
          left,
          top,
          width,
          height,
        };
      })
    );
  } catch (e) {
    console.log('Error on fetch:', e);
    return [];
  }
};

const getWindows = async () => {
  try {
    const appsStr = await execDllPromise('XSplit.Window.GetList', '3');
    const xmlParser = new DOMParser();

    const windowListXMLDoc = xmlParser.parseFromString(appsStr, 'application/xml');
    window.windowListXMLDoc = windowListXMLDoc;
    const windowList = windowListXMLDoc.querySelector('windowList');

    if (!windowList) return [];

    const windows = windowList.querySelectorAll('window')
    if (windows.length) {
      var windowsArray = Array.prototype.slice.call(windows, 0);
      return windowsArray
      .sort((a, b) => a.getAttribute('title').localeCompare(b.getAttribute('title')))
      .map(app => {
        return {
          id: app.getAttribute('processId'),
          hwnd: app.getAttribute('hwnd'),
          name: app.getAttribute('processName'),
          title: app.getAttribute('title'),
          path: app.getAttribute('processPath'),
        };
      });
    }

    return [];
  } catch (e) {
    console.log('Error on fetch:', e);
    return [];
  }
};

@SML-MeSo
Copy link
Collaborator

SML-MeSo commented Apr 1, 2024

Will probably just use this same issue for fixing getAvailableScreens

@SML-MeSo SML-MeSo self-assigned this Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants