Esempio n. 1
0
v8::Handle<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperType, v8::Handle<v8::Object> wrapper)
{
    ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrapper);

    if (!wrapper.IsEmpty()) {
        // Create a V8 Uint8ClampedArray object.
        v8::Handle<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate);
        // Set the "data" property of the ImageData object to
        // the created v8 object, eliminating the C++ callback
        // when accessing the "data" property.
        if (!pixelArray.IsEmpty())
            wrapper->ForceSet(v8AtomicString(isolate, "data"), pixelArray, v8::ReadOnly);
    }
    return wrapper;
}
Esempio n. 2
0
void JsVlcPlayer::initJsApi( const v8::Handle<v8::Object>& exports )
{
    node::AtExit( [] ( void* ) {
        JsVlcPlayer::closeAll();
    } );

    JsVlcInput::initJsApi();
    JsVlcAudio::initJsApi();
    JsVlcVideo::initJsApi();
    JsVlcSubtitles::initJsApi();
    JsVlcPlaylist::initJsApi();

    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope( isolate );

    Local<FunctionTemplate> constructorTemplate = FunctionTemplate::New( isolate, jsCreate );
    constructorTemplate->SetClassName( String::NewFromUtf8( isolate, "VlcPlayer", v8::String::kInternalizedString ) );

    Local<ObjectTemplate> protoTemplate = constructorTemplate->PrototypeTemplate();
    Local<ObjectTemplate> instanceTemplate = constructorTemplate->InstanceTemplate();
    instanceTemplate->SetInternalFieldCount( 1 );

    protoTemplate->Set( String::NewFromUtf8( isolate, "RV32", v8::String::kInternalizedString ),
                        Integer::New( isolate, static_cast<int>( PixelFormat::RV32 ) ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "I420", v8::String::kInternalizedString ),
                        Integer::New( isolate, static_cast<int>( PixelFormat::I420 ) ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );

    protoTemplate->Set( String::NewFromUtf8( isolate, "NothingSpecial", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_NothingSpecial ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Opening", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Opening ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Buffering", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Buffering ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Playing", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Playing ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Paused", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Paused ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Stopped", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Stopped ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Ended", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Ended ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Error", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Error ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );

    Local<String> vlcVersion = String::NewFromUtf8( isolate, libvlc_get_version(), v8::String::kNormalString );
    Local<String> vlcChangeset = String::NewFromUtf8( isolate, libvlc_get_changeset(), v8::String::kNormalString );

    protoTemplate->Set( String::NewFromUtf8( isolate, "vlcVersion", v8::String::kInternalizedString ),
                        vlcVersion,
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "vlcChangeset", v8::String::kInternalizedString ),
                        vlcChangeset,
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );

    SET_CALLBACK_PROPERTY( instanceTemplate, "onFrameSetup", CB_FrameSetup );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onFrameReady", CB_FrameReady );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onFrameCleanup", CB_FrameCleanup );

    SET_CALLBACK_PROPERTY( instanceTemplate, "onMediaChanged", CB_MediaPlayerMediaChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onNothingSpecial", CB_MediaPlayerNothingSpecial );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onOpening", CB_MediaPlayerOpening );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onBuffering", CB_MediaPlayerBuffering );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onPlaying", CB_MediaPlayerPlaying );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onPaused", CB_MediaPlayerPaused );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onForward", CB_MediaPlayerForward );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onBackward", CB_MediaPlayerBackward );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onEncounteredError", CB_MediaPlayerEncounteredError );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onEndReached", CB_MediaPlayerEndReached );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onStopped", CB_MediaPlayerStopped );

    SET_CALLBACK_PROPERTY( instanceTemplate, "onTimeChanged", CB_MediaPlayerTimeChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onPositionChanged", CB_MediaPlayerPositionChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onSeekableChanged", CB_MediaPlayerSeekableChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onPausableChanged", CB_MediaPlayerPausableChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onLengthChanged", CB_MediaPlayerLengthChanged );

    SET_RO_PROPERTY( instanceTemplate, "playing", &JsVlcPlayer::playing );
    SET_RO_PROPERTY( instanceTemplate, "length", &JsVlcPlayer::length );
    SET_RO_PROPERTY( instanceTemplate, "state", &JsVlcPlayer::state );

    SET_RO_PROPERTY( instanceTemplate, "input", &JsVlcPlayer::input );
    SET_RO_PROPERTY( instanceTemplate, "audio", &JsVlcPlayer::audio );
    SET_RO_PROPERTY( instanceTemplate, "video", &JsVlcPlayer::video );
    SET_RO_PROPERTY( instanceTemplate, "subtitles", &JsVlcPlayer::subtitles );
    SET_RO_PROPERTY( instanceTemplate, "playlist", &JsVlcPlayer::playlist );

    SET_RO_PROPERTY( instanceTemplate, "videoFrame", &JsVlcPlayer::getVideoFrame );
    SET_RO_PROPERTY( instanceTemplate, "events", &JsVlcPlayer::getEventEmitter );

    SET_RW_PROPERTY( instanceTemplate, "pixelFormat", &JsVlcPlayer::pixelFormat, &JsVlcPlayer::setPixelFormat );
    SET_RW_PROPERTY( instanceTemplate, "position", &JsVlcPlayer::position, &JsVlcPlayer::setPosition );
    SET_RW_PROPERTY( instanceTemplate, "time", &JsVlcPlayer::time, &JsVlcPlayer::setTime );
    SET_RW_PROPERTY( instanceTemplate, "volume", &JsVlcPlayer::volume, &JsVlcPlayer::setVolume );
    SET_RW_PROPERTY( instanceTemplate, "mute", &JsVlcPlayer::muted, &JsVlcPlayer::setMuted );

    NODE_SET_PROTOTYPE_METHOD( constructorTemplate, "play", jsPlay );
    SET_METHOD( constructorTemplate, "pause", &JsVlcPlayer::pause );
    SET_METHOD( constructorTemplate, "togglePause", &JsVlcPlayer::togglePause );
    SET_METHOD( constructorTemplate, "stop",  &JsVlcPlayer::stop );
    SET_METHOD( constructorTemplate, "toggleMute", &JsVlcPlayer::toggleMute );

    SET_METHOD( constructorTemplate, "close", &JsVlcPlayer::close );

    Local<Function> constructor = constructorTemplate->GetFunction();
    _jsConstructor.Reset( isolate, constructor );

    exports->Set( String::NewFromUtf8( isolate, "VlcPlayer", v8::String::kInternalizedString ), constructor );
    exports->Set( String::NewFromUtf8( isolate, "createPlayer", v8::String::kInternalizedString ), constructor );

    exports->ForceSet( String::NewFromUtf8( isolate, "vlcVersion", v8::String::kInternalizedString ),
                       vlcVersion,
                       static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    exports->ForceSet( String::NewFromUtf8( isolate, "vlcChangeset", v8::String::kInternalizedString ),
                       vlcChangeset,
                       static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
}
Esempio n. 3
0
void set_const(v8::Isolate* isolate, v8::Handle<v8::Object> options,
	char const* name, T const& value)
{
	options->ForceSet(v8pp::to_v8(isolate, name), to_v8(isolate, value),
		v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete));
}