plugin.vk.direct.*

Type Library
Revision Release 2024.3703
Keywords VK, Vkontakte, VK Direct, VK Direct Games
Platforms HTML5

Overview

The VK Direct Games plugin, simple wrapper for VK Mobile. For more information please, refer to Mobile Client API documentation

Important

Note, that APIs would actually work only when app is ran as VK Direct Game on mobile device. To learn more about how to create and deploy your applications see Direct Games documentation.

Syntax

local vk = require("plugin_vk_direct")

Functions

vk.init(function)

Initializes the plugin and sets event listener to handle events from VK APIs. Event structure is described in the following section.


vk.api(methodName, params)

This method call would trigger VK.api(methodName, params) and invoke event name with method set to methodName.


All following functions are wrappers around Mobile SDK methods with same name. Please, refer to documentation for details.

vk.showInviteBox()

vk.showRequestBox(user_id, message, request_key)

vk.showShareBox(message, attachments, target)

vk.showSettingsBox(settings)

vk.showOrderBox(type, item)

vk.showLeaderboardBox(user_result)

This methods are aliases for VK.callMethod(methodName, {arguments}). Result would be dispatched to event listener with method field set to the function name.

Event

Each API call would result in event sent to listener passed to vk.init(). All events have similar 3 fields:

event.name

String. Always "vk".

event.method

String containing name of the method callback is invoked for. For example "init" or "showInviteBox". Note that this would have different value in vk.api() callback.

event.status

String containing "success" or "failure" depending on call results.

event.data

Table containing call results if applicable.

Project Settings

To use this plugin, add an entry into the plugins table of build.settings. When added, the build server will integrate the plugin during the build phase.

settings =
{
    plugins =
    {
        ["plugin.vk.direct"] =
        {
            publisherId = "com.coronalabs"
        },
    },
}

Sample

local loadingText = display.newText( "Loading...", display.contentCenterX, display.contentCenterY, nil, 20)

local vk = require("plugin_vk_direct")

local function vkListener( event )
    if event.method == "init" then
        if event.status == "success" then
            composer.gotoScene( "menu" )
            loadingText:removeSelf( )
        else
            loadingText.text = "VK Initialization error"
        end
    end
end

vk.init(vkListener)