SplitmediaLabsLimited / xjs

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

Editing a Text Source ? #154

Closed Joshimuz closed 7 years ago

Joshimuz commented 7 years ago

Is it really not supported by the API to edit a Text Source easily? The API reference website doesn't even list Text as a source type, and when I tried getting the value via ".getValue()" and ".setValue()" I just get the HTML, so I guess "Text" in XSplit is really just a HTML source. However I assumed that the API would provide an easy way to edit a regular text source, as being able to exit the text on the screen seems like pretty basic functionally to me. Is there a way of editing the text value of the HTML? Other than doing some string wizardry I can't think of an easy method.

mikeybanez commented 7 years ago

You are correct in saying that the Text Source is a full HTML source, and this allows it to support extensive customizations such as our custom scripts. setValue and getValue are really useful primarily for "native" sources like Images or Files for example, but they are mostly there as a fallback for operations which are not abstracted in xjs.

It appears that we are now entering a discussion of letting HTML plugins expose some specific API for extensions to use. While this is not supported now (and neither does the Text Source actually have a public API), for now we might be able to provide you with some undocumented internal calls that might be helpful.

Assigning to @SML-MeSo to investigate a potential solution; right now maybe we just need something that doesn't require changes to the Text plugin or to the plugin framework. We can study how to integrate this into a general "HTML plugin API" flow later on.

SML-MeSo commented 7 years ago

Hii! Sorry about the late reply. Normally, all you need are the HTMLSource's loadConfig, applyConfig and/or requestSaveConfig methods, but this is if the HTML source itself uses the xjs-framework. However, the text source is written way before the framework and as such, doesn't rely on it for configuration. Despite of this, here's what you can do:

  1. Load config of Text source via loadConfig(). This can be used regardless if html uses xjs or not
  2. The configuration object has a "text" property. Change it to whatever you need it to.
  3. We can't use the applyConfig/requestSaveConfig methods, We can, however, use the HTMLItem's call method to directly call the SetConfiguration method of the Text source. This is the internal method that handles config. Pass 'SetConfiguration' as the first parameter and the stringified config object as the second parameter.
textItem.loadConfig().then( config => {
  textConfig = config;
  textConfig['text'] = 'Whatever text';
  return textItem.call('SetConfiguration', JSON.stringify(textConfig));
})

Note: Text source should not be using custom script since custom script overwrites the text property. Also this can only be used via the HTMLItem class, and not the HTMLSource, which is definitely a bug since it should be a source property, already filed as #155

Joshimuz commented 7 years ago

Awesome, thanks a lot @SML-MeSo your explanation and code block works perfectly.