Communicating with Max from within jweb
In Max 7 jweb uses the Chromium Embedded Framework (CEF) for running websites within a Max box. What's new is that you can communicate with the JavaScript of the shown website. Please note that since CEF is in a seperate process, the communication is inherently asynchronous, and you can't rely on having sent and outputted messages within the same event.
Receiving messages from Max
The bindInlet function enables listening to messages being sent to the jweb object from within the JavaScript of the webpage. In order to do that you attach a callback function to certain messages as shown in the example below:
window.max.bindInlet("doSomething", function() {
/*
* trigger functionality without arguments
*
* message 'doSomething'
*/
})
If you'd like to send messages with arguments to the website simply send a list of space delimited values to the jweb object as shown below. You can either access these values as parameters in your listener callback function or use the array-like arguments object if the amount of parameters might vary.
window.max.bindInlet("doSomethingWithArgs", function(a, b) {
/*
* if a fixed set of parameters doesn't meet
* your needs you can use the array-like arguments
* objects in order to gain access to the
* incoming parameters
*
* message: doSomethingWithArgs 1 2
*/
})
Sending messages to Max
Using the outlet function you can output messages from the JavaScript of the shown webpage to the jweb's first outlet.
// output a string
window.max.outlet("foo")
// output a list
window.max.outlet("foo", 1, 2)
// output contents of array with prepended 'foo' message
var ar = [1, 2, 3, 4]
window.max.outlet.apply(window.max, ["foo"].concat(ar))
Additionally you can send messages to Max using the href attribute of an anchor tag if following a certain but simple syntax. Note that a message send this way will be outputted with a prepended 'maxmessage'.
<a href="maxmessage:name/param1/param2">
Interacting with Max dictionaries
Using getDict you can access the contents of a Max dict object from within a website's JavaScript.
var nestedValue
// access dictionary
window.max.getDict("dictName", function(dict) {
// dict is a JS object, so you can do things like
nestedValue = dict.a
})
If you like to set the contents of a dictionary within Max you can use the the setDict function to do that.
var obj = {
a: "1",
b: "2",
c: "3"
}
window.max.setDict("dictName", obj)
See Also
Name | Description |
---|---|
jweb | Web browser |
maxurl | Make HTTP requests |