void VideoPlugin::onPluginReady() { FB::VariantMap::iterator fnd = m_params.find("magic"); if (fnd != m_params.end()) { if(fnd->second.is_of_type<std::string>()) { FB::ptr_cast<VideoAPI>(getRootJSAPI())->setMagic(fnd->second.convert_cast<std::string>()); } } }
bool axWrapper::setReady() { // The call to getRootJSAPI() was removed from PluginCore::setReady() between version // 1.5 and 1.6. Without this call, the plugin JSAPI object may not get created unless // the html <object> tag includes an "onload" param. This plugin relies on the pointer // to the JSAPI object being valid in order to fire events. // Ensure that the JSAPI object has been created, in case the browser hasn't requested it yet. getRootJSAPI(); return PluginCore::setReady(); }
void CorePlugin::onPluginReady() { // Log CorePluginPtr plugin = s_log_plugin.lock(); if(!plugin) { FBLOG_DEBUG("CorePlugin::onPluginReady", "Set as log plugin"); s_log_plugin = FB::ptr_cast<CorePlugin>(shared_from_this()); } FB::VariantMap::iterator fnd = m_params.find("magic"); if (fnd != m_params.end()) { if (fnd->second.is_of_type<std::string>()) { FB::ptr_cast<CoreAPI>(getRootJSAPI())->setMagic(fnd->second.convert_cast<std::string>()); } } }
void Chimera::audio_event( vlc::audio_event_e e ) { JSRootAPIPtr api = boost::static_pointer_cast<JSRootAPI>( getRootJSAPI() ); JSAudioAPIPtr audioApi = api->get_audio().lock(); switch( e ) { case vlc::audio_event_e::mute_changed: audioApi->fire_MuteChanged(); break; case vlc::audio_event_e::volume_changed: audioApi->fire_VolumeChanged(); break; default: assert( false ); } }
void CorePlugin::shutdown() { // This will be called when it is time for the plugin to shut down; // any threads or anything else that may hold a shared_ptr to this // object should be released here so that this object can be safely // destroyed. This is the last point that shared_from_this and weak_ptr // references to this object will be valid FBLOG_DEBUG("CorePlugin::shutdown", "this=" << this); // Log CorePluginPtr plugin = s_log_plugin.lock(); if(plugin == FB::ptr_cast<CorePlugin>(shared_from_this())) { s_log_plugin.reset(); } // Sometimes the object is release before shutdown getRootJSAPI()->shutdown(); }
void FBVLC::on_player_action( vlc::player_action_e action ) { if( m_host->isShutDown() ) return; FBVLCAPIPtr api = boost::static_pointer_cast<FBVLCAPI>( getRootJSAPI() ); switch (action) { case vlc::pa_play: api->fire_PlayEvent(); break; case vlc::pa_pause: api->fire_PauseEvent(); break; case vlc::pa_stop: api->fire_StopEvent(); break; case vlc::pa_current_changed: api->fire_CurrentChangedEvent(); break; } }
//libvlc events arrives from separate thread void Chimera::media_player_event( const libvlc_event_t* e ) { JSRootAPIPtr api = boost::static_pointer_cast<JSRootAPI>( getRootJSAPI() ); FB::BrowserHostPtr h = m_host; void (JSRootAPI::*event_to_fire)(void) = 0; bool fireStateChanged = false; libvlc_state_t newState; bool scheduleNotPlaying = false; switch ( e->type ) { case libvlc_MediaPlayerMediaChanged: event_to_fire = &JSRootAPI::fire_MediaPlayerMediaChanged; break; case libvlc_MediaPlayerNothingSpecial: event_to_fire = &JSRootAPI::fire_MediaPlayerNothingSpecial; fireStateChanged = true; newState = libvlc_NothingSpecial; break; case libvlc_MediaPlayerOpening: event_to_fire = &JSRootAPI::fire_MediaPlayerOpening; fireStateChanged = true; newState = libvlc_Opening; break; case libvlc_MediaPlayerBuffering: h->ScheduleOnMainThread( api, boost::bind( &JSRootAPI::fire_MediaPlayerBuffering, api.get(), e->u.media_player_buffering.new_cache ) ); fireStateChanged = true; newState = libvlc_Buffering; break; case libvlc_MediaPlayerPlaying: { boost::shared_ptr<Chimera> thisPtr = FB::ptr_cast<Chimera>( shared_from_this() ); h->ScheduleOnMainThread( thisPtr, boost::bind( &Chimera::onMediaPlayerPlaying, thisPtr ) ); event_to_fire = &JSRootAPI::fire_MediaPlayerPlaying; fireStateChanged = true; newState = libvlc_Playing; break; } case libvlc_MediaPlayerPaused: event_to_fire = &JSRootAPI::fire_MediaPlayerPaused; scheduleNotPlaying = true; fireStateChanged = true; newState = libvlc_Paused; break; case libvlc_MediaPlayerStopped: event_to_fire = &JSRootAPI::fire_MediaPlayerStopped; scheduleNotPlaying = true; fireStateChanged = true; newState = libvlc_Stopped; break; case libvlc_MediaPlayerForward: event_to_fire = &JSRootAPI::fire_MediaPlayerForward; break; case libvlc_MediaPlayerBackward: event_to_fire = &JSRootAPI::fire_MediaPlayerBackward; break; case libvlc_MediaPlayerEndReached: event_to_fire = &JSRootAPI::fire_MediaPlayerEndReached; scheduleNotPlaying = true; fireStateChanged = true; newState = libvlc_Ended; break; case libvlc_MediaPlayerEncounteredError: event_to_fire = &JSRootAPI::fire_MediaPlayerEncounteredError; scheduleNotPlaying = true; fireStateChanged = true; newState = libvlc_Error; break; case libvlc_MediaPlayerTimeChanged: { double new_time = static_cast<double>( e->u.media_player_time_changed.new_time ); h->ScheduleOnMainThread( api, boost::bind( &JSRootAPI::fire_MediaPlayerTimeChanged, api.get(), new_time ) ); break; } case libvlc_MediaPlayerPositionChanged: h->ScheduleOnMainThread( api, boost::bind( &JSRootAPI::fire_MediaPlayerPositionChanged, api.get(), e->u.media_player_position_changed.new_position ) ); break; case libvlc_MediaPlayerSeekableChanged: h->ScheduleOnMainThread( api, boost::bind( &JSRootAPI::fire_MediaPlayerSeekableChanged, api.get(), e->u.media_player_seekable_changed.new_seekable != 0 ) ); break; case libvlc_MediaPlayerPausableChanged: h->ScheduleOnMainThread( api, boost::bind( &JSRootAPI::fire_MediaPlayerPausableChanged, api.get(), e->u.media_player_pausable_changed.new_pausable != 0 ) ); break; //case libvlc_MediaPlayerTitleChanged: // event_to_fire = &JSRootAPI::fire_MediaPlayerTitleChanged; // break; //case libvlc_MediaPlayerSnapshotTaken: // event_to_fire = &JSRootAPI::fire_MediaPlayerSnapshotTaken; // break; case libvlc_MediaPlayerLengthChanged: { double new_length = static_cast<double>( e->u.media_player_length_changed.new_length ); h->ScheduleOnMainThread( api, boost::bind( &JSRootAPI::fire_MediaPlayerLengthChanged, api.get(), new_length ) ); break; } //case libvlc_MediaPlayerVout: // event_to_fire = &JSRootAPI::fire_MediaPlayerVout; // break; }; if( event_to_fire ) { h->ScheduleOnMainThread( api, boost::bind( event_to_fire, api.get() ) ); } if( fireStateChanged ) { h->ScheduleOnMainThread( api, boost::bind( &JSRootAPI::fire_MediaPlayerStateChanged, api.get(), newState ) ); } if( scheduleNotPlaying ) { boost::shared_ptr<Chimera> thisPtr = FB::ptr_cast<Chimera>( shared_from_this() ); h->ScheduleOnMainThread( thisPtr, boost::bind( &Chimera::onMediaPlayerNotPlaying, thisPtr ) ); } }