PennController.AddHostGlobal Commands

PennController.AddHost( url )

You can use PennController.AddHost to spare you from specifying a URL when you create an element with newAudio, newVideo or newImage. The URL must end with /.

You can pass multiple URL strings (separated by comma) or use AddHost as many times as you want. If you do so, PennController will try to look for audio/images at the host URLs in the order they were provided, and stop looking as soon as it finds one.

Note that you can still directly specify URLs when creating a new element even if you added a host URL with AddHost.

Example:

[js highlight=”1,2″ try=”data”]
PennController.AddHost(“https://files.lab.florianschwarz.net/test/”);
PennController.AddHost(“http://spellout.net/ibexfarm/static/images/”);

PennController(
newImage(“ibex”, “ibex.jpg”)
.print()
,
newImage(“wait”, “https://openclipart.org/image/300px/svg_to_png/23920/Anonymous-Sandglass.png”)
.print()
,
newAudio(“sentence”, “test.mp3”)
.play()
.wait()
);
[/js]

The trial shows two images and plays one audio file. PennController will first try send a request for the file https://myserver/images/square.png and another one for the file https://myserver/audios/square.png. The same is true for the audio file: PennController will first send a request for the file https://myserver/images/shape.mp3 and another one for the file https://myserver/audios/shape.mp3. PennController uses the resource from the first successfully resolving request: in this example, assuming there is a file named square.png at https://myserver/images/ and a file named shape.mp3 at https://myserver/audios/ (and only there), those are the resources that PennController will use (it may still trigger warnings in the console for the unsuccessful requests). PennController will only look for the wait image at http://publicserver/wait.gif, since a full URL is provided there.