Jump to content

publish custom events via javascript api


Tim Edelmann

Recommended Posts

Hey there, 

 

we are currently trying to send custom events via the javascript api (as the title might let you guess... ;)

In a Node-style js-file we're testing the following code, which is sadly not working...

var EventSender = function(server, user, key)
{
	require('isomorphic-fetch')
	var ftrack = require('ftrack-javascript-api');
	this.session = new ftrack.Session(server, user, key);
	if (this.session==null)
	{
		console.log('Error creating session');
		return;
	}
	

	this.DoStuff = function()
	{
		// TODO: find another way to solve this
		// make session available to all subfunctions by creating a 'locally scoped' variable
		// otherwise 'this.session' is only available at the outermost usage (i.e. only on line 28)
		// the nested functions below line 28 don't know about 'this.session'
		var session = this.session;
		if (session==null)
		{
			console.log('Error - No active Session');
			return;
		}

		return session.initializing.then(function()
		{
			var event = new ftrack.Event('infected.custom-event', {foo: 'bar', xyz: true});
			console.log('sending...');
			return session.eventHub.publish(event);
		}).catch(error => {console.log(error);});
	}
}

sender = new EventSender('http://192.168.5.14', 'Admin', 'f22192fc-0cb6-11e8-b2cb-7ab7a47c9dda');
sender.DoStuff();

The resulting error-msg is:

TypeError: Cannot read property 'socket' of null
    at EventHub._runWhenConnected (C:\dev\javascript\ftrack.OS.management\node_modules\ftrack-javascript-api\lib\event_hub.js:307:32)
    at C:\dev\javascript\ftrack.OS.management\node_modules\ftrack-javascript-api\lib\event_hub.js:224:23
    at new Promise (<anonymous>)
    at EventHub.publish (C:\dev\javascript\ftrack.OS.management\node_modules\ftrack-javascript-api\lib\event_hub.js:223:31)
    at C:\dev\javascript\ftrack.OS.management\sendEventTest.js:30:28
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

So for some reason, the local property '_socketIo' in event_hub.js is still null inside the method '_runWhenConnected', which is called in 'publish()' on line 224. 

Can you tell me why that is the case?

having the same setup, we already successfully created calendar-events and other objects. 

 

Side-Question:

Is it possible to send a custom event via javascript-api and receive it via the python-api?

 

 

 

 

Thanks in advance

 

 

 

Tim

Link to comment
Share on other sites

Hi,

Thanks for reaching out.

The JavaScript API does not automatically connect to the event hub. You can either call Session.eventHub.connect() or specify autoConnectEventHub when creating the session.

Read more in the documentation: http://ftrack-javascript-api.rtd.ftrack.com/en/stable/handling_events.html

Quote

Is it possible to send a custom event via javascript-api and receive it via the python-api?

Yep! Both are connected to the same event server and events will be available to either client.

Regards,
Lucas

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...