Hello everyone!
Rookie developer here… (This might be a very silly question but bare with me please)
I’m pretty sure this is possible with now-a-days technology, but have never tried it before.
Well pretty much I want to interact between my program and the webBrowserComponent. Like JS injection or something like that.
I make a simple layout and if I can get any interaction working I can role from there.
In my AudioPlugin project I have a simple Button and Label. On the local HTML WebPage I also just have a Button and Label.
What I want to do is when clicking the button from the plugin change the text of the label (or anything really) on the page, and visa-versa, page button clicks effect the Label on the plugin.
Is this possible?
If yes, could you can give me an as detailed response as possible with code examples? I would really appreciate it!
Here is my code. (Nothing you couldn’t have figured just by looking at the layout :p)
Plugin (header):
#pragma once
#include "../JuceLibraryCode/JuceHeader.h"
#include "PluginProcessor.h"
class WebBrowserInteractionAudioProcessorEditor : public AudioProcessorEditor, Button::Listener
{
public:
WebBrowserInteractionAudioProcessorEditor (WebBrowserInteractionAudioProcessor&);
~WebBrowserInteractionAudioProcessorEditor();
ScopedPointer<Label> thisLable = new Label("label", "A Label ...");
ScopedPointer<TextButton> thisButton = new TextButton("textButton");
ScopedPointer<WebBrowserComponent> thisWebBrowserComponent = new WebBrowserComponent(false);
void WebBrowserInteractionAudioProcessorEditor::buttonClicked(Button* buttonThatWasClicked) override;
void paint (Graphics&) override;
void resized() override;
private:
WebBrowserInteractionAudioProcessor& processor;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebBrowserInteractionAudioProcessorEditor)
};
Plugin (CPP):
#include "PluginProcessor.h"
#include "PluginEditor.h"
WebBrowserInteractionAudioProcessorEditor::WebBrowserInteractionAudioProcessorEditor (WebBrowserInteractionAudioProcessor& p)
: AudioProcessorEditor (&p), processor (p)
{
addAndMakeVisible(thisWebBrowserComponent);
thisWebBrowserComponent->goToURL("file://C:/JUCE/examples/WebBrowserInteraction/index.html");
addAndMakeVisible(thisLable);
addAndMakeVisible(thisButton);
thisButton->addListener(this);
setSize (400, 300);
}
WebBrowserInteractionAudioProcessorEditor::~WebBrowserInteractionAudioProcessorEditor() { }
void WebBrowserInteractionAudioProcessorEditor::buttonClicked(Button* buttonThatWasClicked)
{
if (buttonThatWasClicked == thisButton)
{
// do stuff
}
}
void WebBrowserInteractionAudioProcessorEditor::paint (Graphics& g)
{
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
}
void WebBrowserInteractionAudioProcessorEditor::resized()
{
auto r = getLocalBounds();
auto leftBounds = r.removeFromLeft(100);
thisLable->setBounds(leftBounds.removeFromTop(leftBounds.getHeight() / 2));
thisButton->setBounds(leftBounds);
thisWebBrowserComponent->setBounds(r);
}
Web Page:
<html>
<body>
<label id="lab1">A Label ...</label>
<br>
<button id="btn1">A Button ... </button>
</body>
</html>