How to write a Front plugin ?
The hooks
used in front plugin are:
addHTML
: add some html at the end of the presentationaddHTMLFromFiles
: an array of html files to append in thebody
addScripts
: an array of ressources to load (will be convert toscript
tag withsrc
value as each entry)addSpeakerScripts
: an array of ressources to load (will be convert toscript
tag withsrc
value as each entry) but on speaker viewaddStyles
: an array of ressources to load (will be convert tolink
tag withhref
value as each entry)addSpeakerStyles
: an array of ressources to load (will be convert tolink
tag withhref
value as each entry) but on speaker viewonSlideChange
: javascript code which will be executed after a slide is changedonSpeakerViewSlideChange
: javascript code which will be executed after a slide is changed
Creation of a Webcam plugin
First, create a directory plugins/webcam
in your talk repository
Consider the following plugin.json
:
{
"addStyles": ["./plugins/webcam/webcam.css"],
"addScripts": ["./plugins/webcam/webcam.js"]
}
In the webcam.js
, we will code the connexion to the webcam and the display:
const video = document.querySelector("#webcam");
async function getConnectedDevices(type) {
const devices = await navigator.mediaDevices.enumerateDevices();
return devices.filter((device) => device.kind === type);
}
async function openCamera(cameraId, minWidth, minHeight) {
const constraints = {
video: {
deviceId: cameraId,
width: { min: minWidth },
height: { min: minHeight },
},
};
return await navigator.mediaDevices.getUserMedia(constraints);
}
const webcamize = async () => {
const cameras = await getConnectedDevices("videoinput");
if (cameras && cameras.length > 0) {
cameras.forEach((camera) => {
console.log(camera, window.slidesk.env.WEBCAM);
if (camera.label.includes(window.slidesk.env.WEBCAM)) {
console.log("camera found");
openCamera(camera.deviceId, 1280, 720).then(
(stream) => (video.srcObject = stream)
);
}
});
}
};
webcamize();
Then in the slide, you can add <video autoplay="true" id="webcam"></video>
where you want the webcam.