Last active
August 29, 2015 14:00
-
-
Save stevemayhew/11160122 to your computer and use it in GitHub Desktop.
Demo VMX Detect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
| <!-- Included JS Files --> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js" type="text/javascript"></script> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.js" type="text/javascript"></script> | |
| <script src="vmx_plugin_check.js"></script> | |
| <script> | |
| $(function() { | |
| var vmxCheck = new VmxCheck(); | |
| if (vmxCheck.checkNavigatorPlugins()) { | |
| $('<li>').appendTo('.status').text("Have vmx player plugin installed."); | |
| var $pluginElement = vmxCheck.insertPluginElementNsapi($('#playerContainer')); | |
| $('<li>').appendTo('.status').text("Check vmx enabled."); | |
| var deferred = vmxCheck.notifyWhenEnabled($pluginElement); | |
| deferred.done(function(plugin) { | |
| $('<li>').appendTo('.status').text("Vmx enabled."); | |
| var version = $(plugin)[0].GetVersion(); | |
| $('<li>').appendTo('.status').text("Vmx version: "+version); | |
| }); | |
| } else { | |
| $('<li>').appendTo('.status').text("vmx player plugin NOT installed!"); | |
| } | |
| }) | |
| </script> | |
| </head> | |
| <body> | |
| <h1>Detect Player</h1> | |
| <div id="playerContainer"></div> | |
| <h3>Detection Steps</h3> | |
| <ol class="status"></ol> | |
| </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright 2014 TiVo Inc. All rights reserved. | |
| */ | |
| /** | |
| * simple JS class to detect VMX plugin is installed and enabled. | |
| */ | |
| function VmxCheck() { | |
| var self = this; | |
| $(window).unload(function() { | |
| self.cancelChecks(); | |
| if (self.pluginId) { | |
| try { | |
| var piElemement = $('#' + self.pluginId)[0]; | |
| if (piElemement) { | |
| piElemement.Close(); | |
| piElemement.Unload(); | |
| } | |
| } catch(e) { | |
| console.log("error unloading vmx", e); | |
| } | |
| } | |
| }) | |
| } | |
| VmxCheck.prototype = $.extend(true, {}, { | |
| checkNavigatorPlugins: function() { | |
| var pluginIsInstalled = false; | |
| if (navigator.plugins) { | |
| for (var j = 0; j < navigator.mimeTypes.length && ! pluginIsInstalled; ++j) { | |
| var mt = navigator.mimeTypes[j]; | |
| if (mt.type === 'application/x-viewright-m3u8') { | |
| console.log("ViewRight Installed"); | |
| pluginIsInstalled = true; | |
| } | |
| // console.log(j, mt); | |
| } | |
| } | |
| return pluginIsInstalled; | |
| }, | |
| insertPluginElementNsapi: function($container) { | |
| var self = this; | |
| var $insertInto = $container || $('body'); | |
| var $plugin = $('<object></object>'); | |
| $plugin.attr('type', "application/x-viewright-m3u8"); | |
| $plugin.attr('width', 1); | |
| $plugin.attr('height', 1); | |
| var $appendedPlugin = $plugin.appendTo($insertInto); | |
| self.pluginId = $appendedPlugin.uniqueId().attr('id'); | |
| return $appendedPlugin; | |
| }, | |
| cancelChecks: function() { | |
| var self = this; | |
| if (self.timer) { | |
| clearTimeout(self.timer); | |
| console.log("vmx plugin loaded check timer cancelled"); | |
| } | |
| self.timer = null; | |
| }, | |
| notifyWhenEnabled: function($plugin) { | |
| var deferred = $.Deferred(); | |
| var self = this; | |
| function checkEnabled() { | |
| var isPluginEnabled = 'GetVersion' in $plugin[0]; | |
| self.cancelChecks(); | |
| if (isPluginEnabled) { | |
| console.log("ViewRightWebPlayer.plugin enabled..."); | |
| deferred.resolveWith(this, $plugin); | |
| } else { | |
| console.log("ViewRightWebPlayer.plugin is not enabled, stalling..."); | |
| self.timer = setTimeout(checkEnabled, 500); | |
| } | |
| } | |
| checkEnabled(); | |
| return deferred.promise(); | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment