SplitmediaLabsLimited / xjs

XSplit JS Framework. Make plugins for XSplit Broadcaster, quickly and easily.
Other
39 stars 11 forks source link

"item-created" event for new linked items #245

Closed paul-lrr closed 5 years ago

paul-lrr commented 5 years ago

Is there anyway to detect when a new item has been added that is a link to an existing source? The item-destroyed event fires when a linked item is deleted but I don't see event for a new linked item being created. Not even the item-changed event fires when a new link is added.

mikeybanez commented 5 years ago

Hi @paul-lrr . We can see what we can do here and coordinate with XSplit's core team.

Just curious, what is your use case here? It might help determine the data we can return.

paul-lrr commented 5 years ago

I'm in the process of updating an system that I have been using for various dynamic overlays (scoreboards, captions, graphics, etc). I want to have a central server that keeps a list of which scene(s) a particular source is being used on. I have sources register with the server when they first load, but if I copy and paste a source onto a different scene as a linked item, the new item doesn't load again, so there is no trigger to register that the source is now on two scenes.

The item-destroyed event handles the opposite situation, so I can listen to that event and update the server when a linked item is removed, but I'm not sure how to handle adding linked items.

nelson-temporal commented 5 years ago

Hi paul-lrr,

We are actually planning first to create an event for all 'item-created', then we can just extend it up to 'item-link-created'. For now maybe you could use this simple code to get you started on the functionality you want:

import { ready, Scene, exec } from 'xjs-framework';

ready().then(() => {
  let previousAppOnItemAdded = window.AppOnItemAdded;
  window.AppOnItemAdded = (...args) => {
    previousAppOnItemAdded(args);
    let itemId = args[1];
    Scene.searchItemsById(itemId)
      .then(item => {
        if (item) {
          return item.getSource();
        } else {
          throw new Error('No such item');
        }
      })
      .then(source => {
        return source.getItemList();
      })
      .then(itemList => {
        if (itemList.length > 1) {
          console.log('Item Link Added', itemId);
        } else {
          console.log('New Item Added', itemId);
        }
      })
      .catch(err => {
        console.log(err);
      });
  };
  exec('AppSubscribeEvents');
});

Will just close this ticket for now and create a new one to define the task for this. Please contact us anytime if you have other concerns. Thanks.