1.0.11 • Published 10 months ago

luks-sdk v1.0.11

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

安装

npm i luks-sdk

用法

import LuksSdk from 'luks-sdk';
const luksSdk = new LuksSdk(1, 'zh-CN', false);

CDN 用法

<script src="https://unpkg.com/luks-sdk@1.0.7/dist/luksSdk-iife.js"></script>
<script>
    const luksSdk = new LuksSDK(1, 'zh-CN', false)
</script>

Api 方法

初始化

    // (appId: number, language: string, product: boolean)
    const luksSdk = new LuksSDK(1, 'zh-CN', false)

设置用户信息(Promise)

    // (userId: string, userCode: string)
    luksSdk.setUserInfo('123', '123')

设置业务回调接口

    /**
     * 
    * export interface ICFBizCallback {
        onOpenChargePage?: () => void | Promise<void>
        onGetCurrentRoomId?: () => string | Promise<string>
        onIsRoomOwner?: () => boolean | Promise<boolean>
        onWindowSafeArea?: () => SafeArea | Promise<SafeArea>
        getBaseInfo?: () => BaseInfo | Promise<BaseInfo>
    }
    * export interface SafeArea {
        left?: number,
        top?: number,
        right?: number,
        bottom?: number,
        scaleMinLimit: number
    }

    export interface BaseInfo {
        cid: string,     //渠道id
        gid: string,     //游戏id
        uid: string,     //渠道用户id
        token: string,   //sdk平台令牌
        version: string, //客户端sdk版本号
        language: string,//语言
        widow: string,   //窗囗大小->"宽度x高度'
        rid: string,     //当前房间号
        room_owner: boolean, //是否房主
        ext: string, // 接入方透传数据
    }
    */
   luksSdk.setBizCallback(callback: ICFBizCallback)

拉起一个游戏列表弹窗,其中包含接入方已获得授权的所有游戏

  • 待完善

从服务端获取游戏列表信息(Promise)

    luksSdk.getGameList()

加载半屏游戏(Promise)

    // container: '.className' || document.getElementById('receiver')
    luksSdk.startHalfWindowGame(container: string | HTMLElement, gameId: string, url: string)

加载全屏游戏(Promise)

    // container: '.className' || document.getElementById('receiver')
    luksSdk.startFullWindowGame(container: string | HTMLElement, gameId: string, url: string)

加载横屏游戏(Promise)

    // container: '.className' || document.getElementById('receiver')
    luksSdk.startLandscapeWindowGame(container: string | HTMLElement, gameId: string, url: string)

日志回调

    /**
     * export type LogFn = (tag: string, msg: string) => void
        export interface ICFLogger {
            onDebug?: LogFn
            onInfo?: LogFn
            onWarn?: LogFn
            onError?: LogFn
        }
     */
    luksSdk.setLogger(logger: ICFLogger)

游戏生命周期回调

    /**
     * export interface PreJoinGameRes {
        is_ready: boolean;
        seat: number;
    }

    export interface ICFGameLifecycle {
        onGameLoadFail?: () => void | Promise<void>
        onPreJoinGame?: (userId: string, seat: number) => PreJoinGameRes | Promise<PreJoinGameRes>
        onJoinGame?: (userId: string) => void | Promise<void>
        onGamePrepare?: (userId: string) => void | Promise<void>
        onCancelPrepare?: (userId: string) => void | Promise<void>
        onGameTerminated?: (userId: string) => void | Promise<void>
        onGameOver?: () => void | Promise<void>
        onGameDidFinishLoad?: () => void | Promise<void>
        getGameloadProgress?: (progress: number) => void | Promise<void>
        onSeatAvatarTouch?: (userId: string, seat: number) => void | Promise<void>
        closeGamePage?: () => void | Promise<void>
    }
     */
    luksSdk.setCFGameLifecycle(lifecycle: ICFGameLifecycle)

推拉流接口

    /**
     *  export interface RTCRes {
            complete: boolean;
        }
     *  export interface ICFRTCCallback {
            onCFGamePushSelfRTC?: (push: boolean) => RTCRes | Promise<RTCRes>
            onCFGamePullOtherRTC?: (userId: string, pull: boolean) => RTCRes | Promise<RTCRes>
        }
     */
    luksSdk.setRTCCallback(callback: ICFRTCCallback)

销毁游戏

    luksSdk.destroyGame()

刷新用户信息

    luksSdk.refreshUserInfo()

开始游戏

    luksSdk.gameStart()

移除游戏玩家

    luksSdk.playerRemove(userId: string)

是否关闭游戏背景音乐

    luksSdk.gameBackgroundMusicSet(open: boolean)

是否关闭游戏音效

    luksSdk.gameSoundSet(open: boolean)

设置游戏角色

    luksSdk.setPlayerRole(role: number)

退出游戏

    luksSdk.quitGame(userId: string)

终止游戏

    luksSdk.terminateGame(userId: string)

加入游戏

    luksSdk.joinGame(seatIndex: number)

傻瓜化接入方式

  • 方法一
    import LuksSdk from 'luks-sdk';
    import 'luks-sdk/dist/index.css';
    const luksSdk = new LuksSdk(1, 'zh-CN', false);
    /**
     * container 展示列表容器,打开游戏后容器会被游戏覆盖
     * instance sdk实例
     */
    luksSdk.showGameListDialogshowGameListDialog(container: string, instance: LuksSDK)
  • 方法二(CND)
    <body>
        <div id="receiver" style="width:100%;height:200px;"></div>
    </body>
    <link rel="stylesheet" href="https://unpkg.com/luks-sdk@1.0.7/dist/index.css"/>
    <script src="https://unpkg.com/luks-sdk@1.0.7/dist/luksSdk-iife.js"></script>
    <script>
        window.onload = function() {
            const luksSdk = new LuksSDK(1, 'zh-CN', false)
            luksSdk.showGameListDialog('#receiver', luksSdk)
        }
    </script>
1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago