This is an open-source project. It is not affiliated with Vkontakte LLC.
You can use it in your own project by adding this project as a Defold library dependency. Open your game.project
file and in the dependencies field add a link to the ZIP file of a specific release.
Platform | Status |
---|---|
Browser (HTML5) | Supported âś… |
- đź“š The official documentation.
- đź“š Official package VK Bridge.
- đź’¬ The Telegram chat about Defold for Russian-speaking users.
To get started, you need to initialize the SDK using the init
method.
local vkbridge = require("vkbridge.vkbridge")
local function init_handler(self, err)
if err then
print("Something bad happened :(", err)
else
--
-- SDK is ready!
-- From this moment, you can use all available functions, i.e. invoke ads, get player data, etc.
--
end
end
function init(self)
vkbridge.init(init_handler)
end
[vk_bridge]
auto_init = true
wv_banners = true
interstitial_day_limit = 50
interstitial_hour_limit = 10
interstitial_delay = 90
auto_init
boolean optional The application initializes the VKBridge on startup. To prevent VKBridge from being initialized, setfalse
. Then the initialization will be whenvkbridge.init(init_handler)
is called. Defaulttrue
.wv_banners
boolean optional Loads a script containing a WebView banner. Defaultfalse
.interstitial_day_limit
number optional Set a limited number per day for interstitial ads. Default:no limit
. If set to0
, then there isno limit
.interstitial_hour_limit
number optional Set a limited number per hour for interstitial ads. Default:no limit
. If set to0
, then there isno limit
.interstitial_delay
number optional Set a limit per seconds for interstitial ads. Default:no limit
. If set to0
, then there isno limit
.
VKBridge JavaScript SDK uses ES6 Promise for asynchronous operations. For Lua API promises were replaced with callback functions with arguments (self, err, result)
, where
self
userdata - Script self reference.err
table - Error code if something went wrong. If successful:err = nil
.result
table - Data if the operation should return something.
Initialize the Vk Bridge
Parameters
callback
function required callback with response data
Sends a message to native client and returns the object with response data
Parameters
name
string required The VK Bridge methoddata
table|nil optional Message data objectcallback
function optional callback with response data
Subscribes a function to events listening.
The function will handle each vkbridge.send
and some additional events. In order not to miss events, you can subscribe before calling vkbridge.init
.
Parameters
fn
function required Function to be subscribed to events.function(self, data)
Unsubscribes a function from events listening
Parameters
fn
function required Event subscribed function
Checks if an event is available on the current device
Parameters
method
string required The VK Bridge method
Returns true
if VK Bridge is running in mobile app, or false
if not
Returns true
if VK Bridge is running in iframe, or false
if not
Returns true
if VK Bridge is running in embedded app, or false
if not
Returns true
if VK Bridge is running in standalone app, or false
if not
All of these functions can be called with vkbridge.send
. They are written for convenience.
Check if there is the interstitial ad available
Parameters
callback
function required callback with response data
Show interstitial ads
Parameters
callback
function required callback with response data
Check if there is the rewarded ad available to serve
Parameters
use_waterfall
boolean required Whether to use the mechanism for displaying interstitial advertising in the absence of rewarded video.callback
function required callback with response data
Show rewarded ads
Parameters
use_waterfall
boolean required Whether to use the mechanism for displaying interstitial advertising in the absence of rewarded video.callback
function required callback with response data
Set the value of the variable whose name is passed in the key
parameter. Key
life is 1 year.
Parameters
key
string required Key name, [a-zA-Z_-0-9]. The maximum length is 100 characters.value
string required The value of the variable. Only the first 4096 bytes are stored.callback
function required callback with response data
Return the values of the variables.
Parameters
key
string|table required Names of keys or key [a-zA-Z_-0-9]. Can be a table or a stringcallback
function required callback with response data
Return the names of all variables.
Parameters
count
number required The number of variable names to get information about.offset
number|nil required The offset required to select a particular subset of variable names.callback
function required callback with response data
Clear interstitial limits if used
Allows you to get basic data about the profile of the user who launched the application
Parameters
callback
function required callback with response data
WebView Banner is a banner which is displayed either above or below the application. It is available only for mobile devices running in the VKontakte application.
Be sure to enable wv_banners = true in the game.project.
Load WebView banner. Available for mobile only.
Parameters
callback
function required callback with response data
Unload WebView banner. Available for mobile only. Return true
on success.
Show WebView banner. Available for mobile only. Return true
on success.
Hide WebView banner. Returns true
on success.
Refresh WebView banner. Available for mobile only.
Parameters
callback
function required callback with response data
Set WebView banner configs.
Parameters
position
string required Banner location. Can betop
orbottom
.count
number Number of banners in a column. Default1
Vk advises to make limiting the display of ads.
The platform itself does not block display of ads. However, ads can be turned off for you if they think that you are cheating on it.
Limits only work for vkbridge.show_interstitial(callback) function.
Limits use storage to save data for day and hour. Keys: interstitial_day_limit
and interstitial_hour_limit
.
To the received data will be added some key(exceeded
, delay_exceeded
, hour_limit_exceeded
, day_limit_exceeded
), If the limit is exceeded. The table looks like this:
{
delay_exceeded = true, -- if delay limit is exceeded
hour_limit_exceeded = true, -- if hour limit is exceeded
day_limit_exceeded = true, -- if day limit is exceeded
result = true, -- the result will always be true
exceeded = true -- if any limit is exceeded
}
Made by PotatoJam.
This project uses the source code of YaGames.
For example used:
MIT license.