tudada-sdk-types
v0.0.1-3
Published
TypeScript type definitions for TudadaSDK - H5 web game SDK for Tudada platform
Maintainers
Readme
tudada-sdk-types
TypeScript type definitions for TudadaSDK - H5 web game SDK for Tudada platform.
Installation
npm install tudada-sdk-typesUsage
Global Types (Recommended)
After installing tudada-sdk-types, global types are automatically available without any import:
// No import needed! Types are automatically recognized
TudadaSDK.login({
success: (res) => console.log('Login code:', res.code),
fail: (err) => console.error('Login failed:', err.errMsg),
});
const systemInfo = TudadaSDK.getSystemInfoSync();
console.log('Platform:', systemInfo.platform);This works because the package includes global.d.ts which declares the global TudadaSDK and tudadaSDK variables.
Import Types
You can also import types directly:
import type {
LoginOption,
LoginSuccessResult,
SystemInfo,
UserInfo,
RewardedVideoAd,
} from 'tudada-sdk-types';
// Use types in your code
const handleLogin = (options: LoginOption) => {
TudadaSDK.login(options);
};
const systemInfo: SystemInfo = TudadaSDK.getSystemInfoSync();Available Types
Auth API
LoginOption,LoginSuccessResultCheckSessionOptionGetUserInfoOption,GetUserInfoSuccessResult,UserInfo
Storage API
SetStorageOption,GetStorageOption,GetStorageSuccessResultRemoveStorageOption,ClearStorageOptionStorageInfoTudadaStore,TudadaStoreGetOption,TudadaStoreSaveOption
System API
SystemInfo,GetSystemInfoOptionWindowInfo,GetWindowInfoOptionAppBaseInfo,GetAppBaseInfoOptionDeviceInfo,GetDeviceInfoOptionPlatform,SafeArea
UI API
MenuButtonBoundingClientRect
Device API
VibrateShortOption,VibrateLongOption,VibrateTypeShowKeyboardOption,HideKeyboardOptionOnKeyboardInputCallback,OnKeyboardConfirmCallback,OnKeyboardCompleteCallback
Clipboard API
SetClipboardDataOptionGetClipboardDataOption,GetClipboardDataSuccessResult
Ad API
CreateRewardedVideoAdOptionRewardedVideoAd
Lifecycle API
OnShowCallback,OnShowCallbackResultOnHideCallback,OnHideCallbackResultExitMiniProgramOption,RestartMiniProgramOption
SDK Interface
ITudadaSDK- Main SDK interface
Common Types
GeneralCallbackResultMock<T>
Global Variables
When TudadaSDK is loaded via script tag, the following global variables are available:
TudadaSDK/tudadaSDK- Main SDK instancewindow.TudadaSDK/window.tudadaSDK
Example
import type { SystemInfo, UserInfo, RewardedVideoAd } from 'tudada-sdk-types';
// Get system info
const systemInfo: SystemInfo = TudadaSDK.getSystemInfoSync();
console.log('Platform:', systemInfo.platform);
console.log('Screen size:', systemInfo.screenWidth, 'x', systemInfo.screenHeight);
// Login
TudadaSDK.login({
success: (res) => {
console.log('Login code:', res.code);
// Get user info
TudadaSDK.getUserInfo({
success: (userRes) => {
const user: UserInfo = userRes.userInfo;
console.log('Nickname:', user.nickName);
console.log('Avatar:', user.avatarUrl);
},
});
},
});
// Create rewarded video ad
const ad: RewardedVideoAd = TudadaSDK.createRewardedVideoAd({
adUnitId: 'your-ad-unit-id',
});
ad.onLoad(() => console.log('Ad loaded'));
ad.onError((err) => console.error('Ad error:', err.errMsg));
ad.onClose((res) => {
if (res.isEnded) {
console.log('Ad completed - give reward!');
}
});
ad.load().then(() => ad.show());License
MIT
