LTI sources: LTI Message Handler

ltisource_message_handler
Maintained by Picture of Colin BernardColin Bernard
This Moodle LTI Source plugin allows communication between an LTI tool and a consumer site.
37 sites
82 downloads
4 fans
Current versions available: 1

LTI Message Handler

by Western Canadian Learning Network.  


This Moodle LTI Source plugin allows communication between an LTI tool and a consumer site. It is meant to replicate message handling functions implemented in Canvas. Thus, if an LTI provider makes use of Canvas' functions, this plugin will work similarly.    

The main purpose of this plugin is to allow iFrame resizing. The LTI iFrames in Moodle are laughably small and impossible to view course content in. With this plugin installed, an LTI tool provider may send messages to the tool consumer instructing it to resize the iFrame.  

See the screenshots which show an LTI book with and without this plugin installed.  


Installation:  

This plugin should be installed on the tool consumer site. See "Usage" for how to make use of this plugin as a tool provider.

  • Download this repository.  
  • Extract the ZIP to 'mod/lti/source/'.  
  • The folder name within the source directory should be "message_handler".  
  • Login to your Moodle site as an administrator and install the plugin.

or

  • Login to your Moodle site as an admin and go to Administration -> Site administration -> Plugins -> Install plugins.  
  • Upload the ZIP file.  


Usage:  

Once the plugin is installed on the tool consumer site, the tool provider may communicate with it as follows.

// Send message to the tool consumer to resize the iframe. Height will be accepted as an integer or a string.
window.parent.postMessage(JSON.stringify({subject: 'lti.frameResize', height: 1000}), '*');
// Send message to the tool consumer to resize the iframe.
window.parent.postMessage(JSON.stringify({subject: 'lti.scrollToTop'}), '*');
// Send a message to the tool consumer to remove the iframe border. window.parent.postMessage(JSON.stringify({subject: 'lti.removeBorder'}), '*');

For example, if a tool provider is returning a page 'index.html' to be displayed in the iframe, they should add a JavaScript file similar to above.

Note: While you can install this plugin on your site receiving LTI content, the LTI provider must implement one of the above to actually use the functions.

Possible message subjects:  

  • lti.frameResize  
  • lti.scrollToTop  
  • lti.removeBorder

I should be adding more subjects as I continue development.

If you enjoyed this plugin, please vote for it to be included in Moodle core! https://tracker.moodle.org/browse/MDL-64972

Created by Colin Bernard (colinjbernard@hotmail.com) for Western Canadian Learning Network.

Screenshots

Screenshot #0
Screenshot #1
Screenshot #2
Screenshot #3

Contributors

Picture of Colin Bernard
Colin Bernard (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Plugins bot
    Fri, Feb 15, 2019, 3:00 PM
    Approval issue created: CONTRIB-7623
  • Picture of Laurent Dairaine
    Fri, Mar 1, 2019, 4:01 PM
    Thank you for this great plugin. Could it be possible to have a LTI message implementing a dynamic height setting, depending of real size of consumer page ?
  • Picture of Colin Bernard
    Mon, Mar 4, 2019, 4:09 AM
    You are very welcome! Glad it could be of use. Unfortunately I don't believe what you are looking for would work. The height of the consumer page area is dependent on the height of the iframe (content). Not the other way around.
  • Picture of Laurent Dairaine
    Mon, Mar 4, 2019, 4:30 AM
    Sorry, just a bug in my question...I was asking about a LTI message implementing a dynamic height setting depending of the real size of the PROVIDER page (not consumer). In fact, I try to connect with LTI two moodle instances and I would like to use (short) courses of a first instance from the other one. But I don't know before what will be the size of the content because it depends on the course included. So it is why I would need this dynamic height message. Thanks for your help!
  • Picture of Colin Bernard
    Mon, Mar 4, 2019, 4:39 AM
    Hmm I believe the current function lti.frameResize should work for what you need. Within your provider code, I would create some JavaScript code which runs once you know the size of the content, perhaps on a body onload? In my examples above I provided "height: 1000". However, you can use JavaScript/JQuery to detect the size of the course content and provide the height of that, for example height = $('#some-div').outerHeight(false). That is how I am using this plugin with my own custom provider.

    However, it sounds like you might be using Moodle's built in LTI provider functionality? I haven't tested this plugin with that, as it is intended for custom provider applications in which you can implement your own functions to send messages. If you are using Moodle's built in LTI provider, you may have to edit that core code to send the frameResize messsages.
Please login to post comments