Skip to content

Commit 26a44e9

Browse files
Update msn, youtube, playgama
1 parent 8c613ae commit 26a44e9

6 files changed

Lines changed: 147 additions & 10 deletions

File tree

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "playgama-bridge",
3-
"version": "1.31.3",
3+
"version": "1.31.4",
44
"description": "One SDK for cross-platform publishing HTML5 games",
55
"main": "index.js",
66
"scripts": {
@@ -19,14 +19,14 @@
1919
},
2020
"repository": {
2121
"type": "git",
22-
"url": "git+https://github.com/playgama/bridge"
22+
"url": "git+https://github.com/Playgama/bridge"
2323
},
2424
"author": "Playgama",
2525
"license": "LGPL-3.0-or-later",
2626
"bugs": {
27-
"url": "https://github.com/playgama/bridge/issues"
27+
"url": "https://github.com/Playgama/bridge/issues"
2828
},
29-
"homepage": "https://github.com/playgama/bridge",
29+
"homepage": "https://github.com/Playgama/bridge",
3030
"dependencies": {},
3131
"devDependencies": {
3232
"@babel/core": "^7.17.8",

scripts/platforms.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,13 @@ while ((match = regex.exec(source)) !== null) {
1616
}
1717
}
1818

19-
module.exports = { ALL_PLATFORM_IDS }
19+
// Platforms that must always be bundled together with the key platform.
20+
const PLATFORM_BUNDLE_EXTRAS = {
21+
playgama: ['standalone'],
22+
}
23+
24+
const expandPlatforms = (platforms) => Array.from(
25+
new Set(platforms.flatMap((id) => [id, ...(PLATFORM_BUNDLE_EXTRAS[id] || [])])),
26+
)
27+
28+
module.exports = { ALL_PLATFORM_IDS, expandPlatforms }

src/platform-bridges/MsnPlatformBridge.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class MsnPlatformBridge extends PlatformBridgeBase {
100100
return true
101101
}
102102

103+
get isAddToHomeScreenSupported() {
104+
return typeof this._platformSdk?.promptInstallAsync === 'function'
105+
}
106+
103107
// leaderboards
104108
get leaderboardsType() {
105109
return LEADERBOARD_TYPE.NATIVE
@@ -295,6 +299,27 @@ class MsnPlatformBridge extends PlatformBridgeBase {
295299
})
296300
}
297301

302+
addToHomeScreen() {
303+
let promiseDecorator = this._getPromiseDecorator(ACTION_NAME.ADD_TO_HOME_SCREEN)
304+
if (!promiseDecorator) {
305+
promiseDecorator = this._createPromiseDecorator(ACTION_NAME.ADD_TO_HOME_SCREEN)
306+
this._platformSdk.promptInstallAsync()
307+
.then((outcome) => {
308+
if (outcome === 'accepted') {
309+
this._resolvePromiseDecorator(ACTION_NAME.ADD_TO_HOME_SCREEN)
310+
return
311+
}
312+
313+
this._rejectPromiseDecorator(ACTION_NAME.ADD_TO_HOME_SCREEN)
314+
})
315+
.catch((error) => {
316+
this._rejectPromiseDecorator(ACTION_NAME.ADD_TO_HOME_SCREEN, error)
317+
})
318+
}
319+
320+
return promiseDecorator.promise
321+
}
322+
298323
// leaderboards
299324
leaderboardsSetScore(id, score) {
300325
return new Promise((resolve, reject) => {
@@ -725,7 +750,7 @@ class MsnPlatformBridge extends PlatformBridgeBase {
725750
#updatePlayerInfo(data) {
726751
if (data) {
727752
this._isPlayerAuthorized = true
728-
this._playerId = data.playerId
753+
this._playerId = data.playerId ?? data.publisherPlayerId
729754
this._playerName = data.playerDisplayName
730755
this._playerExtra = data
731756
this.#isPaymentsSupported = data.userAccountType.toLowerCase() === 'personal'

src/platform-bridges/PlaygamaPlatformBridge.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,17 +494,22 @@ class PlaygamaPlatformBridge extends PlatformBridgeBase {
494494
}
495495

496496
#getPlayer() {
497-
if (!this.#isPlayerAuthorizationSupported) {
497+
if (typeof this._platformSdk.userService?.getUser !== 'function') {
498498
this._playerApplyGuestData()
499499
return Promise.resolve()
500500
}
501501

502502
return new Promise((resolve) => {
503503
this._platformSdk.userService.getUser()
504504
.then((player) => {
505+
// The SDK id is used even for unauthorized players;
506+
// without it the locally generated guest id stays in place.
507+
if (player.id) {
508+
this._playerId = player.id
509+
}
510+
505511
if (player.isAuthorized) {
506512
this._isPlayerAuthorized = true
507-
this._playerId = player.id
508513
this._playerName = player.name
509514
this._playerPhotos = player.photos
510515
this._playerExtra = player

src/platform-bridges/YoutubePlatformBridge.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class YoutubePlatformBridge extends PlatformBridgeBase {
6262
return false
6363
}
6464

65+
get isClipboardSupported() {
66+
return false
67+
}
68+
6569
// leaderboards
6670
get leaderboardsType() {
6771
return LEADERBOARD_TYPE.NATIVE
@@ -71,6 +75,8 @@ class YoutubePlatformBridge extends PlatformBridgeBase {
7175

7276
#subscribeNotification = null
7377

78+
#videoPreview = null
79+
7480
initialize() {
7581
if (this._isInitialized) {
7682
return Promise.resolve()
@@ -81,6 +87,7 @@ class YoutubePlatformBridge extends PlatformBridgeBase {
8187

8288
if (this.deviceType === DEVICE_TYPE.DESKTOP) {
8389
this.#subscribeNotification = this.#createSubscribeNotification()
90+
this.#videoPreview = this.#createVideoPreview()
8491
}
8592

8693
waitFor('ytgame').then(() => {
@@ -280,6 +287,10 @@ class YoutubePlatformBridge extends PlatformBridgeBase {
280287
this.#subscribeNotification.remove()
281288
this.#subscribeNotification = null
282289
}
290+
if (this.#videoPreview) {
291+
this.#videoPreview.remove()
292+
this.#videoPreview = null
293+
}
283294
return Promise.resolve()
284295
}
285296
default: {
@@ -506,6 +517,93 @@ class YoutubePlatformBridge extends PlatformBridgeBase {
506517
document.body.appendChild(container)
507518
return container
508519
}
520+
521+
#createVideoPreview() {
522+
const previews = (this._options.videoPreviews ?? [])
523+
.filter((preview) => Boolean(preview?.image && preview?.videoId))
524+
if (previews.length === 0) {
525+
return null
526+
}
527+
528+
const { image, videoId } = previews[Math.floor(Math.random() * previews.length)]
529+
530+
if (!document.getElementById('bridge-youtube-video-preview-styles')) {
531+
const style = document.createElement('style')
532+
style.id = 'bridge-youtube-video-preview-styles'
533+
style.textContent = `
534+
#bridge-youtube-video-preview {
535+
position: fixed;
536+
bottom: -24px;
537+
right: 24px;
538+
width: min(256px, 40vw);
539+
border-radius: 16px;
540+
overflow: hidden;
541+
background-color: #000;
542+
box-shadow: 0 8px 24px 0 rgba(0, 0, 0, 0.4);
543+
cursor: pointer;
544+
opacity: 0;
545+
z-index: 9999999;
546+
animation: bridge-yt-preview-rise 285ms ease-out 590ms forwards;
547+
}
548+
549+
#bridge-youtube-video-preview .bridge-yt-preview-image {
550+
display: block;
551+
width: 100%;
552+
aspect-ratio: 16 / 9;
553+
object-fit: cover;
554+
user-select: none;
555+
-webkit-user-drag: none;
556+
}
557+
558+
#bridge-youtube-video-preview .bridge-yt-preview-play {
559+
position: absolute;
560+
top: 50%;
561+
left: 50%;
562+
width: 48px;
563+
height: 34px;
564+
transform: translate(-50%, -50%);
565+
pointer-events: none;
566+
}
567+
568+
@keyframes bridge-yt-preview-rise {
569+
0% { bottom: -24px; opacity: 0; }
570+
40% { bottom: 25.6px; opacity: 1; }
571+
48% { bottom: 33.6px; }
572+
60% { bottom: 32px; }
573+
70% { bottom: 30.4px; }
574+
79% { bottom: 28.8px; }
575+
88% { bottom: 27.2px; }
576+
95% { bottom: 25.6px; }
577+
100% { bottom: 24px; opacity: 1; }
578+
}
579+
`
580+
document.head.appendChild(style)
581+
}
582+
583+
const container = document.createElement('div')
584+
container.id = 'bridge-youtube-video-preview'
585+
586+
const img = document.createElement('img')
587+
img.className = 'bridge-yt-preview-image'
588+
img.src = image
589+
img.alt = ''
590+
img.draggable = false
591+
container.appendChild(img)
592+
593+
container.insertAdjacentHTML('beforeend', `
594+
<svg class="bridge-yt-preview-play" viewBox="0 0 68 48" fill="none" xmlns="http://www.w3.org/2000/svg">
595+
<path d="M66.52 7.74C65.74 4.81 64.03 2.33 61.1 1.55C55.79 0.13 34 0 34 0C34 0 12.21 0.13 6.9 1.55C3.97 2.33 2.27 4.81 1.48 7.74C0.06 13.05 0 24 0 24C0 24 0.06 34.95 1.48 40.26C2.27 43.19 3.97 45.67 6.9 46.45C12.21 47.87 34 48 34 48C34 48 55.79 47.87 61.1 46.45C64.03 45.67 65.74 43.19 66.52 40.26C67.94 34.95 68 24 68 24C68 24 67.94 13.05 66.52 7.74Z" fill="#FF0033"/>
596+
<path d="M45 24L27 14V34L45 24Z" fill="white"/>
597+
</svg>
598+
`)
599+
600+
container.addEventListener('click', () => {
601+
window.ytgame?.engagement.openYTContent({ id: videoId }).catch(() => {})
602+
})
603+
604+
document.body.appendChild(container)
605+
return container
606+
}
509607
}
510608

511609
export default YoutubePlatformBridge

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const webpack = require('webpack')
44
const ESLintPlugin = require('eslint-webpack-plugin')
55
const TerserPlugin = require('terser-webpack-plugin')
66
const packageJson = require('./package.json')
7-
const { ALL_PLATFORM_IDS } = require('./scripts/platforms')
7+
const { ALL_PLATFORM_IDS, expandPlatforms } = require('./scripts/platforms')
88

99
const platformDirName = 'platform-bridges'
1010
const CDN_BASE_URL = `https://bridge.playgama.com/v${packageJson.version.split('.')[0]}/stable/`
@@ -101,7 +101,7 @@ const createConfig = (targetPlatforms = [], { noLint = false } = {}) => ({
101101

102102
module.exports = (env = {}, argv = {}) => {
103103
const targetPlatform = env.platform || ''
104-
const targetPlatforms = targetPlatform ? targetPlatform.split(',') : []
104+
const targetPlatforms = targetPlatform ? expandPlatforms(targetPlatform.split(',')) : []
105105
const noLint = Boolean(env.noLint)
106106
const isDevelopment = argv.mode === 'development'
107107

0 commit comments

Comments
 (0)