-
Notifications
You must be signed in to change notification settings - Fork 277
Networking Introduction
Chromely via CefGlue provides 2 different ways of Inter-process Communication (IPC) between the Renderer and the Browser.
- Generic Message Routing
- Ajax HTTP/XHR
These allow Chromely to receieve JavaScript requests initated by the Renderer, processed by the Browser (C#) and returned Json data response to the Renderer.
The configuration of an IPC workflow involves:
- Create a Controller class
- Register an Action or Command method in the Controller class
- Register the Controller class
- Register a scheme (http, custom, etc)
- Create a JavaScript request in the Renderer html
- An action is the normal way to do IPC. There is a request and a response.
- Commands are fire-and-forget requests. As you might already have guessed, no response is returned.
More information on how to implement Command methodes.
Every IPC workflow requires a Controller class. The class must inherit ChromelyController.
public class CustomController : ChromelyController
{
}
An action method can be registered in the custom controller constructor or as an attribute decorated method.
- Constructor type
public DemoController()
{
RegisterGetRequest("/democontroller/movies", GetMovies);
RegisterPostRequest("/democontroller/movies", SaveMovies);
}
private ChromelyResponse GetMovies(ChromelyRequest request)
{
}
private ChromelyResponse SaveMovies(ChromelyRequest request)
{
}
- Attribute decorated type
[HttpGet(Route = "/democontroller/movies")]
public ChromelyResponse GetMovies(ChromelyRequest request)
{
}
[HttpPost(Route = "/democontroller/movies")]
public ChromelyResponse SaveMovies(ChromelyRequest request)
{
}
The class CustomController must be registered. Registration can be done either by registering the Assembly where the class is created or registering via the Container
- Registering the assembly class can be done in 2 ways:
- Adding the fullpath of the assembly in the configuration config file
"controllerAssemblies": [
"Chromely.External.Controllers.dll"
],
- Adding it in the configuration object.
var config = new DefaultConfiguration();
config.ControllerAssemblies = new List<ControllerAssemblyInfo>();
config.ControllerAssemblies.RegisterServiceAssembly("Chromely.External.Controllers.dll");
- Register the Controller class via the Container:
public class DemoChromelyApp : ChromelyBasicApp
{
public override void Configure(IChromelyContainer container)
{
base.Configure(container);
container.RegisterSingleton(typeof(ChromelyController), Guid.NewGuid().ToString(), typeof(CustomController));
}
}
For details on registering a custom scheme please see Custom Http Registration.
To trigger an actual request, an event must must be set up in the HTML file.
A sample:
function getMovies() {
var request = {
"method": "GET",
"url": "/democontroller/movies",
"parameters": null,
"postData": null
};
window.cefQuery({
request: JSON.stringify(request),
onSuccess: function (response) {
- -- process response
}, onFailure: function (err, msg) {
console.log(err, msg);
}
});
}
Chromely
Getting Started
Networking
Resources
Debugging
Detailed documentation on:
- Getting Started
- Configuring Chromely
- Loading Html
- Resource Handling
- Configuring Message Routing
- Register Ajax/XHR Handlers
- JavaScript Execution
- Scheme Registration
- Scheme Handlers
- Custom Http Handlers
- How to use commands
- Custom CEF Handlers
- Chromely on Raspberry Pi
- How to use app settings
- CEF binaries download
- Using DevTools