Skip to content

MonitorBridge

Classes

MonitorBridge

Typedefs

MonitorMessage : Object

MonitorBridge

Kind: global class

new MonitorBridge()

Send and recieve messages between instances of your wallpaper across monitors if your wallpaper is running in a multimonitor environment. Each instance of your wallpaper is assigned to a unique monitor and thus has a unique monitor ID string (something like "\\\\.\\DISPLAY1"). You can use these IDs to send messages between separate instances of your wallpaper. This is useful for coordinating events between different instances if you want your mod to behave differently across monitors.

monitorBridge.requestId() ⇒ Promise.<string>

Request this window's monitor ID.

Kind: instance method of MonitorBridge
Returns: Promise.<string> - Resolves to a string containing this window's monitor ID.
Example

monitorBridge.requestId().then((myId) => {
     console.log('My monitor id is: ' + myId); // probably will look like "\\\\.\\DISPLAY1"
});

monitorBridge.requestSiblingIds() ⇒ Promise.<Array.<string>>

Request the monitor IDs of sibling windows. A sibling is another window running on another monitor but running the same mod instance as yours. That is, it will include wallpapers in other monitors only if they are running your wallpaper. Monitors assigned to wallpapers are excluded.

Kind: instance method of MonitorBridge
Returns: Promise.<Array.<string>> - Resolves to an array of strings containing the monitor ID strings of this window's siblings.
Example

monitorBridge.requestSiblingIds().then((siblingIds) => {
     for (const siblingId of siblingIds) {
         console.log('Sibling ID: ' + siblingId);
         // do something with each one
     }
     console.log('We have ' + siblingIds.length + ' simultaneous instances of our wallpaper running on different monitors');
});

monitorBridge.send(recipientId, data)

Send a message to a window belonging to another monitor.

Kind: instance method of MonitorBridge

Param Type Description
recipientId string The monitor ID of the intended recipient.
data Object The contents of the message to send.

Example

// Send a message to all siblings
someData = {
     hello: true,
     myFavoriteNumber: 4
};

monitorBridge.requestSiblingIds().then((siblingIds) => {
     siblingIds.forEach((id) => {
         monitorBridge.send(id, someData);
     });
})

monitorBridge.on(eventName, callback)

Add an event listener.

Kind: instance method of MonitorBridge

Param Type Description
eventName 'message' 'message' events fire when another instance sends a message to this monitor ID.
callback function Resolves to a MonitorMessage object, containing both senderId and message.

Example

monitorBridge.on('message', (e) => {
     console.log('Incoming message from: ' + e.senderId);
     console.log('Message contents: ' + JSON.stringify(e.message));
     // You can also respond:
     const recipientId = e.senderId;
     monitorBridge.send(recipientId, {
         someString: 'I got your message',
         someData: 3
     });
})

monitorBridge.once(eventName, callback)

Add a one-time event listener that removes itself after firing.

Kind: instance method of MonitorBridge

Param Type
eventName 'message'
callback function

monitorBridge.off(eventName, callback)

Remove an event listener.

Kind: instance method of MonitorBridge

Param Type
eventName 'message'
callback function

MonitorMessage : Object

Kind: global typedef
Properties

Name Type Description
senderId string The monitor ID of the sender.
data Object The contents of the message being recieved.