@cntrl-site/sdk-nextjs 1.1.3 → 1.1.5-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,7 +61,7 @@ const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibili
61
61
  (0, react_1.useEffect)(() => {
62
62
  if (!vimeoPlayer || !imgRef)
63
63
  return;
64
- if (play === 'on-click' && !controls) {
64
+ if (play === 'on-click') {
65
65
  setIsCoverVisible(true);
66
66
  }
67
67
  vimeoPlayer.on('pause', (e) => {
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AudioPlayer = void 0;
4
+ const howler_1 = require("howler");
5
+ class AudioPlayer {
6
+ constructor() {
7
+ this.audio = new howler_1.Howl({
8
+ src: ['https://cdn.cntrl.site/client-app-files/hover.b226066e.mp3'],
9
+ volume: 1,
10
+ });
11
+ }
12
+ play() {
13
+ this.audio.play();
14
+ }
15
+ }
16
+ exports.AudioPlayer = AudioPlayer;
@@ -14,10 +14,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.InteractionsRegistry = void 0;
15
15
  const sdk_1 = require("@cntrl-site/sdk");
16
16
  const Item_1 = require("../components/Item");
17
+ const AudioPlayer_1 = require("./AudioPlayer");
17
18
  class InteractionsRegistry {
18
19
  constructor(article, layoutId) {
19
20
  this.layoutId = layoutId;
20
21
  this.ctrls = new Map();
22
+ this.audioPlayer = new AudioPlayer_1.AudioPlayer();
21
23
  const { interactions } = article;
22
24
  this.items = this.unpackItems(article);
23
25
  const activeStatesIds = interactions.reduce((map, inter) => {
@@ -139,6 +141,9 @@ class InteractionsRegistry {
139
141
  for (const trigger of interaction.triggers) {
140
142
  itemsToNotify.add(trigger.itemId);
141
143
  }
144
+ if (triggerType === 'click') {
145
+ this.playClickSound();
146
+ }
142
147
  this.notifyItemCtrlsChange(Array.from(itemsToNotify));
143
148
  this.notifyTransitionStartForItems(transitioningItems, activeStateId);
144
149
  }
@@ -235,5 +240,8 @@ class InteractionsRegistry {
235
240
  }
236
241
  return stages;
237
242
  }
243
+ playClickSound() {
244
+ this.audioPlayer.play();
245
+ }
238
246
  }
239
247
  exports.InteractionsRegistry = InteractionsRegistry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.1.3",
3
+ "version": "1.1.5-alpha.0",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.ts",
@@ -51,7 +51,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
51
51
 
52
52
  useEffect(() => {
53
53
  if (!vimeoPlayer || !imgRef) return;
54
- if (play === 'on-click' && !controls) {
54
+ if (play === 'on-click') {
55
55
  setIsCoverVisible(true);
56
56
  }
57
57
  vimeoPlayer.on('pause', (e) => {
@@ -77,6 +77,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
77
77
  vimeoPlayer!.play();
78
78
  setIsCoverVisible(false);
79
79
  };
80
+
80
81
  const isInteractive = opacity !== 0;
81
82
  useEffect(() => {
82
83
  onVisibilityChange?.(isInteractive);
@@ -0,0 +1,16 @@
1
+ import { Howl } from 'howler';
2
+
3
+ export class AudioPlayer {
4
+ private audio: Howl;
5
+
6
+ constructor() {
7
+ this.audio = new Howl({
8
+ src: ['https://cdn.cntrl.site/client-app-files/hover.b226066e.mp3'],
9
+ volume: 1,
10
+ });
11
+ }
12
+
13
+ play() {
14
+ this.audio.play();
15
+ }
16
+ }
@@ -7,6 +7,7 @@ import {
7
7
  ItemAny,
8
8
  } from '@cntrl-site/sdk';
9
9
  import { isItemType } from '../components/Item';
10
+ import { AudioPlayer } from './AudioPlayer';
10
11
 
11
12
  export class InteractionsRegistry implements InteractionsRegistryPort {
12
13
  private ctrls: Map<ItemId, ItemInteractionCtrl> = new Map();
@@ -16,7 +17,7 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
16
17
  private interactionStateMap: InteractionStateMap;
17
18
  private itemsStages: ItemStages;
18
19
  private activeStateIdInteractionIdMap: Record<StateId, InteractionId>;
19
-
20
+ private audioPlayer = new AudioPlayer();
20
21
  constructor(article: Article, private layoutId: string) {
21
22
  const { interactions } = article;
22
23
  this.items = this.unpackItems(article);
@@ -137,6 +138,9 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
137
138
  for (const trigger of interaction.triggers) {
138
139
  itemsToNotify.add(trigger.itemId);
139
140
  }
141
+ if (triggerType === 'click') {
142
+ this.playClickSound();
143
+ }
140
144
  this.notifyItemCtrlsChange(Array.from(itemsToNotify));
141
145
  this.notifyTransitionStartForItems(transitioningItems, activeStateId);
142
146
  }
@@ -234,6 +238,10 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
234
238
  }
235
239
  return stages;
236
240
  }
241
+
242
+ private playClickSound() {
243
+ this.audioPlayer.play();
244
+ }
237
245
  }
238
246
 
239
247
  type ItemStages = (TransitioningStage | ActiveStage)[];