1.0.11 • Published 10 months ago

luksdk-web v1.0.11

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

安装

npm i luksdk-web

用法

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

CDN 用法

<script src="https://unpkg.com/luksdk-web@1.0.0/dist/luksSdk-iife.js"></script>
<script>
    const luksSdk = new LuksSDK(1, 'zh-CN', "xxx","xxx")
</script>

Api 方法

初始化

    // (appId: number, language: string, apiUrl:string, wsUrl:string)
    const luksSdk = new LuksSDK(1, 'zh-CN', "xxx","xxx")

设置用户信息(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,//语言
        window: 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 RTCSelfRes {
            push:boolean;
            complete: boolean;
        }
        export interface RTCOtherRes {
            userId:string,
            pull:boolean;
            complete: boolean;
        }
     *  export interface ICFRTCCallback {
            onCFGamePushSelfRTC?: (push: boolean) => RTCSelfRes | Promise<RTCSelfRes>
            onCFGamePullOtherRTC?: (userId: string, pull: boolean) => RTCOtherRes | Promise<RTCOtherRes>
        }
     */
    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)
1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago