npm package: @onetouch/otfeim
Description: OneTouch Front-End Integration Module
Latest version: 1.1.0-alpha.0

# OneTouch Front-End Integration Module 

OTFEIM is a JavaScript library for applying compliance requirements of different jurisdictions.


## Installation

This module designed to be installed by Gateway script. Nevertheless it can be installed directly

as standalone (Preferred)

```bash
<!-- relative way -->
<script src="ot-feim/latest/dist/index.umd.min.js"></script>
<!-- static way -->
<script src="https://.../ot-feim/latest/dist/index.umd.min.js"></script>

```
or as a nodeJS/npm
```bash
npm install @onetouch/otfeim --save
```

## Usage

### Instance
Get instance when script is loaded.
```
// get instance when script is loaded
const OTFEIM = window.OTFEIM
```
or
```
import { OTFEIM } from "@onetouch/otfeim";
```

### Configuration
```
const conf = {
   realityCheck: {
     enabled: complianceConf.responsibleGambling,
     lang: languageManager.locale,
     currency: currency,
     currencyPrecision: precision,
     devicePlatform: IS_MOBILE === true ? 'mobile' : 'desktop',
     rgPageUrl: complianceConf.rgUrl,
     jurisdiction: complianceConf.jurisdiction

     lossLimit: 0,
     lossLimitMax: balanceController.availableBalance,
     
     sessionDurations: complianceConf.sessionDuration,
     sessionDuration: complianceConf.sessionDuration[0],
     
     notificationIntervals = complianceConf.notificationInterval,
     notificationInterval = complianceConf.notificationInterval[0],

     onShowHistory: () => this.showHandHistory(),
     onExitToLobby: () => this.exitToLobby(),
     onPageOpen: () => this.updateLayout()
   },
   gameTitle: {
     enabled: true,
     gameTitleText: languageManager.getString( 'CLASSIC_BLACKJACK' )
   },
   server: {
     baseUrl: router.baseUrl,
     authToken: router.authToken,
     configId: router.configId,
     gameType: "BLACKJACK"
   },
   latencyCheck: {
     enabled: complianceConf.poorInternetConnection
   },
   inactivityCheck: {
     enabled: complianceConf.inactivityTimeout > 0,
     inactivityTimeout = complianceConf.inactivityTimeout * 60// convert from min to sec
   },
   storageData: storageData
}
OTFEIM.configure(conf)
```

### Round Status
Inform OTFEIM when the round is started and ended. Responsible gambling dialogs should not disturb players from the gameplay, so dialogs will occur only when the round is inactive. 

Please note:
* In-game Free Spins, Gamble, Jackpots are considered as part of the round, because players still have some playing bets and chance to win.
* Winning animations should be considered as part of the round. Change round status to inactive when all required winning animations are finished and players can start the next round (spin/deal button became active). It will prevent interrupting gameplay by responsible gambling dialogs.
* Autoplay - each spin/deal is considered as a new round and round status should be changed at least for a moment. This should give to OTFEIM possibility to block gameplay in case if it required (etc. loss limits reached, session limit reached... )

```
OTFEIM.setRoundActive: (roundActive: boolean) => void
```

### Features Status
Inform OTFEIM when there are some active features, which shouldn't be interrupted by responsible gambling dialogs. 
For example:
* Loading screen
* Game menus

```
OTFEIM.setGameBusy: (gameBusy: boolean) => void
```

### Loss Limit Validation
According to one of the responsible gambling requirements: players should not spend more money than they set as a limit. 
Following function must be called before round start for limit validations:

```
OTFEIM.realityCheckBetValidation: (bet: number, isMinBet: boolean) => boolean
```
where
* `bet` - total bet to be deducted from the player's balance.
* `isMinBet` - flag to mark is it minimum allowed bet or not. It is used for proper wordings in notification dialog. 
* returns - true - bet is allowed; false - bet is not allowed (corresponding notification dialog should be automatically displayed by OTFEIM). 

For loss limit validation all bets and wins must be reported to OTFEIM. Following functions should be called as soon as the engine (server) response is received:
```
OTFEIM.addBet: (bet: number) => void
```
```
OTFEIM.addWin: (win: number) => void
```
Responsible gambling requirements allow users to change limits they would like to spend. Send to OTFEIM actual player’s balance, which will be applied for maximum allowed loss limit.
```
OTFEIM.setBalance: (balance: number) => void
```

### Show Responsible Gambling Setup Page
Force to show a responsible gambling page, where the player can change his limits. It ignores round status and game business.

```
OTFEIM.showRCSetupPage: () => void
```

### Show Responsible Gambling Statement
Force to show a responsible gambling statement dialog, where the player can check his limits.

```
OTFEIM.showRCStatement: () => void
```

### Show Game Title
Display or hide title of the game.

```
OTFEIM.showGameTitle: (show: boolean) => void
```

### Version of OTFEIM
Returns version of OTFEIM.

```
OTFEIM.version: string
```

## For OTFEIM developers

Developed with Node ```14.17.0``` and npm ```6.14.13```

### Building

```
npm i
npm run build
```

### Generate documentation
``` npm run docs ```

## Changelog

1.0.0 - initial version, which supports:

* Reality check
* Inactivity check
* Latency check
* Game title