-
Notifications
You must be signed in to change notification settings - Fork 0
Event listen
The Listen module provides a simple event system that lets you poll EcoleDirecte for changes and respond immediately when something new happens—like receiving a brand-new grade, a message, or a new school activity!
Let's set up a daemon to watch for new events in real-time.
import { startPolling, on } from "linkdirecte";
// 1. Listen for new grades
const unsubscribeGrades = on("newGrade", (grade) => {
console.log(`🎉 New Grade Posted! ${grade.valeur}/${grade.noteSur} in ${grade.libelleMatiere}`);
});
// 2. Listen for new messages
on("newMessage", (message) => {
console.log(`✉️ New Message from ${message.fromName || "Unknown"}: "${message.subject}"`);
});
// 3. Listen for new timeline entries
on("newTimelineEntry", (entry) => {
console.log(`📅 New Activity: [${entry.typeElement}] ${entry.titre}`);
});
// 4. Listen for polling errors (useful if servers go down)
on("pollingError", (error) => {
console.error("⚠️ An error occurred while polling:", error);
});
// 5. Start the engine! (Polls every 30 seconds)
startPolling({ interval: 30000 });Spins up a background timer that regularly pulls data from EcoleDirecte, computes differences, and emits events when updates are discovered.
function startPolling(config?: PollingConfig): voidIf called while polling is already active, it stops the existing timer before starting a new one. The first poll fires immediately—there is no initial delay.
-
config(optional):-
interval(number): How often the SDK should query EcoleDirecte, specified in milliseconds. Defaults to60000(1 minute).
-
Shuts down the background timer and stops all polling requests.
function stopPolling(): voidRegisters a listener function for a specific event.
function on(event: string, handler: (data: any) => void): () => void-
event(string): The event name to listen for (see Event Types Reference). -
handler((data: any) => void): Callback invoked with the event payload whenever the event fires.
An unsubscribe function. Call it to quickly remove the listener and clean up memory!
const unsubscribe = on("newGrade", (g) => console.log(g));
// Stop listening later
unsubscribe();Explicitly removes a previously registered listener. You must pass the same function reference that was originally passed to on.
function off(event: string, handler: (data: any) => void): void-
event(string): The event name the handler was registered under. -
handler((data: any) => void): The exact function reference originally passed toon.
const handler = (grade) => console.log(grade);
on("newGrade", handler);
// Remove later — same reference required
off("newGrade", handler);Tip: Prefer the unsubscribe function returned by
onwhen you only need to remove a single listener. Useoffwhen you need to remove a listener without holding onto the unsubscribe closure.
Linkdirecte processes changes across multiple student channels. You can subscribe to these events:
| Event | Emitted When | Payload Type |
|---|---|---|
"newGrade" |
A new grade is entered into the system. | GradeEntry |
"newMessage" |
A new message is received in the student's mailbox. | MessageEntry |
"newTimelineEntry" |
A new event occurs on the student's activity feed. | TimelineEntry |
"pollingError" |
An API fetch fails due to credentials, token expiry, or a network timeout. | Error |
© 2026 typeof (Scolup) | Licensed under AGPL 3.0