{"id":15723196,"url":"https://github.com/potatojam/defold-vkbridge","last_synced_at":"2025-05-13T04:01:17.781Z","repository":{"id":161530379,"uuid":"447120276","full_name":"potatojam/defold-vkbridge","owner":"potatojam","description":"Vk Bridge implementation for the Defold game engine.","archived":false,"fork":false,"pushed_at":"2023-08-05T15:24:41.000Z","size":330,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-11T07:13:02.076Z","etag":null,"topics":["defold","defold-library","defold-module","vk-bridge","vk-sdk"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/potatojam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-12T07:36:50.000Z","updated_at":"2024-10-06T18:21:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"0d7303f4-9f4f-466b-a846-799658580b19","html_url":"https://github.com/potatojam/defold-vkbridge","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potatojam%2Fdefold-vkbridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potatojam%2Fdefold-vkbridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potatojam%2Fdefold-vkbridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potatojam%2Fdefold-vkbridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/potatojam","download_url":"https://codeload.github.com/potatojam/defold-vkbridge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253870863,"owners_count":21976613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defold","defold-library","defold-module","vk-bridge","vk-sdk"],"created_at":"2024-10-03T22:10:37.809Z","updated_at":"2025-05-13T04:01:17.011Z","avatar_url":"https://github.com/potatojam.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":["Programming Language"],"readme":"# VK Bridge for Defold\n\n**This is an open-source project. It is not affiliated with Vkontakte LLC.**\n\n## Installation\n\nYou can use it in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your `game.project` file and in the dependencies field add **a link to the ZIP file of a [specific release](https://github.com/potatojam/defold-vkbridge/tags).**\n\n## Supported Platforms\n\n| Platform        | Status      |\n| --------------- | ----------- |\n| Browser (HTML5) | Supported ✅ |\n\n## Getting Started\n\n* [📚 The official documentation](https://dev.vk.com/bridge/getting-started).\n* [📚 Official package VK Bridge](https://github.com/VKCOM/vk-bridge).\n* [💬 The Telegram chat about Defold](https://t.me/DefoldEngine) for Russian-speaking users.\n\n## Initialization\n\nTo get started, you need to initialize the SDK using the `init` method.\n\n```lua\nlocal vkbridge = require(\"vkbridge.vkbridge\")\n\nlocal function init_handler(self, err)\n    if err then\n        print(\"Something bad happened :(\", err)\n    else\n        --\n        -- SDK is ready!\n        -- From this moment, you can use all available functions, i.e. invoke ads, get player data, etc.\n        --\n    end\nend\n\nfunction init(self)\n    vkbridge.init(init_handler)\nend\n```\n\n## The `game.project` Settings\n\n```ini\n[vk_bridge]\nauto_init = true\nwv_banners = true\ninterstitial_day_limit = 50\ninterstitial_hour_limit = 10\ninterstitial_delay = 90\n```\n\n* `auto_init` \u003ckbd\u003eboolean\u003c/kbd\u003e _optional_ The application initializes the **VKBridge** on startup. To prevent **VKBridge** from being initialized, set `false`. Then the initialization will be when `vkbridge.init(init_handler)` is called. Default `true`.\n* `wv_banners` \u003ckbd\u003eboolean\u003c/kbd\u003e _optional_ Loads a script containing a [WebView banner](#webview-banner). Default `false`.\n* `interstitial_day_limit` \u003ckbd\u003enumber\u003c/kbd\u003e _optional_ Set a [limited](#limits) number per day for interstitial ads. Default: `no limit`. If set to `0`, then there is `no limit`.\n* `interstitial_hour_limit` \u003ckbd\u003enumber\u003c/kbd\u003e _optional_ Set a [limited](#limits) number per hour for interstitial ads. Default: `no limit`. If set to `0`, then there is `no limit`.\n* `interstitial_delay` \u003ckbd\u003enumber\u003c/kbd\u003e _optional_ Set a [limit](#limits) per seconds for interstitial ads. Default: `no limit`. If set to `0`, then there is `no limit`.\n\n## Lua API\n\nVKBridge JavaScript SDK uses ES6 Promise for asynchronous operations. For Lua API promises were replaced with callback functions with arguments `(self, err, result)`, where\n\n- `self` \u003ckbd\u003euserdata\u003c/kbd\u003e - Script self reference.\n- `err` \u003ckbd\u003etable\u003c/kbd\u003e - Error code if something went wrong. If successful: `err = nil`.\n- `result` \u003ckbd\u003etable\u003c/kbd\u003e - Data if the operation should return something.\n\n### `vkbridge.init(callback)`\n\nInitialize the Vk Bridge\n\n**Parameters**\n\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.send(name, [, data[, callback]])`\n\nSends a message to native client and returns the object with response data\n\n**Parameters**\n\n- `name` \u003ckbd\u003estring\u003c/kbd\u003e _required_ The VK Bridge method\n- `data` \u003ckbd\u003etable|nil\u003c/kbd\u003e _optional_ Message data object\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _optional_ callback with response data\n \n### `vkbridge.subscribe(fn)`\n\nSubscribes a function to events listening.\nThe function will handle each `vkbridge.send` and some additional events. In order not to miss events, you can subscribe before calling `vkbridge.init`.\n\n**Parameters**\n\n- `fn` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ Function to be subscribed to events. `function(self, data)`\n\n### `vkbridge.unsubscribe(fn)`\n\nUnsubscribes a function from events listening\n\n**Parameters**\n\n- `fn` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ Event subscribed function\n\n### `vkbridge.supports(method)`\n\nChecks if an event is available on the current device\n\n**Parameters**\n\n- `method` \u003ckbd\u003estring\u003c/kbd\u003e _required_ The VK Bridge method\n\n### `vkbridge.is_webview()`\n\nReturns `true` if VK Bridge is running in mobile app, or `false` if not\n\n### `vkbridge.is_iframe()`\n\nReturns `true` if VK Bridge is running in iframe, or `false` if not\n\n### `vkbridge.is_embedded()`\n\nReturns `true` if VK Bridge is running in embedded app, or `false` if not\n\n### `vkbridge.is_standalone()`\n\nReturns `true` if VK Bridge is running in standalone app, or `false` if not\n\n## Additional Lua API\n\nAll of these functions can be called with `vkbridge.send`. They are written for convenience.\n\n### `vkbridge.check_interstitial(callback)`\n\nCheck if there is the interstitial ad available\n\n**Parameters**\n\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.show_interstitial(callback)`\n\nShow interstitial ads\n\n**Parameters**\n\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.check_rewarded(use_waterfall, callback)`\n\nCheck if there is the rewarded ad available to serve\n\n**Parameters**\n\n- `use_waterfall` \u003ckbd\u003eboolean\u003c/kbd\u003e _required_ Whether to use the mechanism for displaying interstitial advertising in the absence of rewarded video.\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.show_rewarded(use_waterfall, callback)`\n\nShow rewarded ads\n\n**Parameters**\n\n- `use_waterfall` \u003ckbd\u003eboolean\u003c/kbd\u003e _required_ Whether to use the mechanism for displaying interstitial advertising in the absence of rewarded video.\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.storage_set(key, value, callback)`\n\nSet the value of the variable whose name is passed in the `key` parameter. `Key` life is 1 year.\n\n**Parameters**\n\n- `key` \u003ckbd\u003estring\u003c/kbd\u003e _required_ Key name, [a-zA-Z_\\-0-9]. The maximum length is 100 characters.\n- `value` \u003ckbd\u003estring\u003c/kbd\u003e _required_ The value of the variable. Only the first 4096 bytes are stored.\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.storage_get(key, callback)`\n\nReturn the values of the variables.\n\n**Parameters**\n\n- `key` \u003ckbd\u003estring|table\u003c/kbd\u003e _required_ Names of keys or key [a-zA-Z_\\-0-9]. Can be a table or a string\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.storage_get_keys(key, callback)`\n\nReturn the names of all variables.\n\n**Parameters**\n\n- `count` \u003ckbd\u003enumber\u003c/kbd\u003e _required_ The number of variable names to get information about.\n- `offset` \u003ckbd\u003enumber|nil\u003c/kbd\u003e _required_ The offset required to select a particular subset of variable names.\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.clear_limits()`\n\nClear interstitial [limits](#limits) if used\n\n### `vkbridge.get_user_info(callback)`\n\nAllows you to get basic data about the profile of the user who launched the application\n\n**Parameters**\n\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n## WebView Banner\n\nWebView 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.\n\n![WebView Banner](docs/wv-banners.jpg)\n\nBe sure to enable **wv_banners = true** in the **game.project**.\n\n### `vkbridge.load_wv_banner(callback)`\n\nLoad WebView banner. Available for mobile only.\n\n**Parameters**\n\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.unload_wv_banner()`\n\nUnload WebView banner. Available for mobile only. Return `true` on success.\n\n### `vkbridge.show_wv_banner()`\n\nShow WebView banner. Available for mobile only. Return `true` on success.\n\n### `vkbridge.hide_wv_banner()`\n\nHide WebView banner. Returns `true` on success.\n\n### `vkbridge.refresh_wv_banner(callback)`\n\nRefresh WebView banner. Available for mobile only.\n\n**Parameters**\n\n- `callback` \u003ckbd\u003efunction\u003c/kbd\u003e _required_ callback with response data\n\n### `vkbridge.set_wv_banner_configs(position, count)`\n\nSet WebView banner configs.\n\n**Parameters**\n\n- `position` \u003ckbd\u003estring\u003c/kbd\u003e _required_ Banner location. Can be `top` or `bottom`.\n- `count` \u003ckbd\u003enumber\u003c/kbd\u003e Number of banners in a column. Default `1`\n\n## Limits\n\nVk advises to make limiting the display of ads.\nThe 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.\nLimits only work for [vkbridge.show_interstitial(callback)](#vkbridgeshow_interstitialcallback) function.\nLimits use storage to save data for day and hour. Keys: `interstitial_day_limit` and `interstitial_hour_limit`.\nTo 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:\n\n```lua\n{\n  delay_exceeded = true, -- if delay limit is exceeded\n  hour_limit_exceeded = true, -- if hour limit is exceeded\n  day_limit_exceeded = true, -- if day limit is exceeded\n  result = true, -- the result will always be true\n  exceeded = true -- if any limit is exceeded\n}\n```\n\n## Credits\n\nMade by [PotatoJam](https://github.com/potatojam).\n\nThis project uses the source code of [YaGames](https://github.com/indiesoftby/defold-yagames).\n\nFor example used:\n\n[Dirty Larry](https://github.com/andsve/dirtylarry)\n\n[Druid](https://github.com/Insality/druid)\n\n### License\n\nMIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotatojam%2Fdefold-vkbridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpotatojam%2Fdefold-vkbridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotatojam%2Fdefold-vkbridge/lists"}