MOS plugins support

This API allows third party plugins to create and edit MOS plugin data (add MOS XMLs) in iNews stories.
MOS data is displayed as production queues in an iNEWS story.

Static plugin support

For static plugins (and, basically, any panes in MediaCentral) there are special global events which allow the plugin
to work with MOS data:

  • AVMosInit
    AVMosInit event fires when MOS module is loading. It provides a callback function that registers the plugin.
    The function accepts a configuration object of the structure:
1
2
3
4
{
id: 'mospluginid', //id of the plugin (either mositemeditorpogid or mositembrowserprogid)
className: 'iNEWS.MOSItemEditor' //class name for MOS plugin objects
}

This event fires during initial page load. The plugin has to be registered for proper functioning.

  • AVMosItemEdit
    AVMosItemEdit event is fired when any MOS item is opened for editing in an iNEWS story. This event has MOS data in the
    payload. The MOS data object has the following structure:
1
2
3
4
5
{
id: 'mositemid', //id of the plugin
data: '<mosxml>', //MOS XML data as a sting
modifyData: function //A function, that you can call to pass new MOS XML to the story pane
}

The modifyData function is the way you can pass your changes to the story pane. Basically, you just call it, passing a new MOS XML as an argument:

1
mosPayload.modifyData(newMosXml);

Usage example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var MyPlugin = ..... //Plugin description
MyPlugin.info = {
id: 'mosplugin-id',
className: 'iNEWS.MOSPlugin',
name: 'MOS Plugin',
viewType: 'mos-plugin'
};
AV.Application.getEventHandler().bind('AVMosInit', function (e, registerPlugin) {
// this event handler receives two arguments, the second one being a function that lets you register your plugin
registerPlugin(MyPlugin.info);
});
AV.Application.getEventHandler().bind('AVMosItemEdit', function (e, mosPayload) {
// this event handler receives two arguments
// mosPayload is an object, containing the information about the MOS item which is being edited, including the XML data
if (data.id === MyPlugin.info.id) {
MyPlugin.setData(data);
}
});

Simple API wrapper

The approach described above might seem complex. To simplify it a little bit, you can use an API wrapper similar to the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var AV = window.AV;
var plugins = [];
var editListeners = [];

if (AV && AV.Application && AV.Application.getEventHandler) {
AV.Application.getEventHandler().bind('AVMosInit', function (e, register) {
plugins.forEach(register);
});

AV.Application.getEventHandler().bind('AVMosItemEdit', function (e, mosPayload) {
var listeners = editListeners.filter(function (listener) {
return mosPayload.id === listener.id;
});

return listeners.forEach(function (listenerObj) {
if (typeof listenerObj.callback === 'function') {
listenerObj.callback(mosPayload);
}
});
});
}

function registerPlugin(pluginInfo) {
plugins.push(pluginInfo);

return {
onMosItemEdit: onMosItemEditTriggered(pluginInfo.id)
}
}

function onMosItemEditTriggered(pluginId) {
return function (callback) {
var listener = {
id: pluginId,
callback: callback
};

editListeners.push(listener);

return function () {
var index = editListeners.indexOf(listener);
if (index >= 0) {
editListeners.splice(index, 1);
}
}
}
}

module.exports = registerPlugin;

Now, you can simply use the registerPlugin function in your module:

1
2
3
4
5
//Registering plugin and receiving an object, that contains a onMosItemEdit function:
var mosApi = registerMosPlugin(pluginInfo);
//using onMosItemEdit function to provide a callback function that will be called when a MOS item is edited in the story pane
var unregisterMosListener = mosApi.onMosItemEdit(onMosEdit);
// unregisterMosListener function allows you to stop listening to MOS edit events

The onMosEdit function now receives the same mosPayload as described above.

For MCS 2.10.1

For the systems that have MCS version 2.10.1 you can use the static plugin dependency mechanism to create a mos-item-editor module along with your view.
In order to do this, you need to add some additional properties to your avid property in module.exports:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module.exports = {
"avid": [
{
provides: ['views', 'mos-editor'],
create: function create() {
return {
factory: function () {
// creating your static MCUX view
},
config: config, // view configuration
//mosPlugin info - basically the same object you pass to the init events' register plugin function
mosPluginInfo: {
id: '...' // id of your MOS plugin (either mositemeditorpogid or mositembrowserprogid)
// this id defines what MOS data can be edited by this plugin
},
// this property expects a function, that will be called, when your plugin is registered in the system
onMosEditorInit: function (api) {
// the function receives an api object containing only one function - onMosItemEdit
var unsubscribeFromMosEdit = api.onMosItemEdit(
onMosEdit // a function that will be called when someone tries to edit a MOS cue in the story pane
);
// when called, this function returns another function, that lets you unsubscribe from the API
}
}
}
}
]
};