This is a demo Windows Forms application that embeds an HTML 5 application and shares data over the OpenFin Runtime Inter Application Bus. The demo leverages the OpenFin Runtime, the Openfin.WinForm EmbeddedView control
- Follow the NuGet install instructions.
Once installed add a reference to Openfin.WinForm:
using System;
using System.Windows.Forms;
using Openfin.WinForm;
namespace WinForms.Test
{
public partial class Form1 : Form
{
...
Now place an EmbeddedView control in the screen:
var OpenFinEmbeddedView = new EmbeddedView();
//Assuming we have a Panel control named panel1
panel1.Controls.Add(OpenFinEmbeddedView);
The Runtime Options object specifies the OpenFin Runtime being used, options include: target runtime (alpha, beta, 32/64 bits...etc), the ability to use remote debugging or specifiying the RVM location, you can read more about options in our Docs:
var runtimeOptions = new Openfin.Desktop.RuntimeOptions
{
Version = "alpha",
EnableRemoteDevTools = true,
RemoteDevToolsPort = 9090
};
The Application Options object allows you to configure the OpenFin Application being embedded, options include: name, URL, icon and window options, you can read more about options in our Docs:
var appOptions = new Openfin.Desktop.ApplicationOptions("of-chart",
"of-chart-uuid", "http://cdn.openfin.co/embed-web/chart.html");
The EmbeddedView will need to be initialized with both the RuntimeOptions object and the ApplicationOptions object:
OpenFinEmbeddedView.Initialize(runtimeOptions, appOptions);
To programmatically react to when the EmbeddedView has loaded its content, initialized and is ready to be displayed you can subscribe to the OnReady event:
OpenFinEmbeddedView.OnReady += (sender, e) =>
{
//Any Interactions with the UI must be done in the right thread.
Utils.InvokeOnUiThreadIfRequired(this, () =>
textBlockReady.Text = "OpenFinEmbeddedView is ready");
}
The OpenFinEmbeddedView allows you to embed web applicatons, these will have their own render process and sandbox, but it also allows you to embed child windows that can share the same render process and sandbox, adding the risk of one window crashing the other but using less resources.
OpenFinEmbeddedView.OnReady += (sender, e) =>
{
//We need to create our WindowOptions Object
var windowOptions = new WindowOptions("jsdocs", "http://cdn.openfin.co/jsdocs/3.0.1.5/");
//Assuming we have added a second EmbeddedView called OpenFinEmbeddedViewChild we initialize it.
OpenFinEmbeddedViewChild.Initialize(runtimeOptions, OpenFinEmbeddedView.OpenfinApplication, windowOptions)
}
Every EmbeddedView control that shares a RuntimeOptions object will share a connection to the OpenFin Runtime. You can obtain this singleton object via the Runtime.GetRuntimeInstance function. It allows you to publish and subscribe to Inter Application Bus messages, react to disconnect events, and initiate connect calls (this is optional and unnecessary in the case where one or more EmbeddedView control has been initialized).
var openFinRuntime = Runtime.GetRuntimeInstance(runtimeOptions);
openFinRuntime.Connect(() =>
{
//Any Interactions with the UI must be done in the right thread.
Utils.InvokeOnUiThreadIfRequired(this, () =>
textBlockConnected.Text = "OpenFin Runtime is connected");
//subscribe to hello-from-bus messages from any application
openFinRuntime.InterApplicationBus.subscribe("*", "hello-from-bus", (senderUuid, topic, data) =>
{
var dataAsJObject = JObject.FromObject(data);
Utils.InvokeOnUiThreadIfRequired(this, () =>
textBlockMessage.Text = dataAsJObject.GetValue("message"));
});
});
MIT
The code in this repository is covered by the included license.
However, if you run this code, it may call on the OpenFin RVM or OpenFin Runtime, which are covered by OpenFin’s Developer, Community, and Enterprise licenses. You can learn more about OpenFin licensing at the links listed below or just email us at [email protected] with questions.
https://openfin.co/developer-agreement/
https://openfin.co/licensing/
Please enter an issue in the repo for any questions or problems. Alternatively, please contact us at [email protected]