@hive-ng/web-sdk
v0.1.4
Published
HIVE-NG browser SDK for game clients.
Maintainers
Readme
HIVE-NG Web SDK
Browser SDK for HIVE-NG game clients.
Install
npm install @hive-ng/web-sdkBasic Usage
import { createHiveNg } from "@hive-ng/web-sdk";
const hive = createHiveNg({
gatewayUrl: "https://gateway.example.com",
projectId: "project-id",
apiKey: "api-key",
persistSession: true,
});
await hive.init();
const loginProviders = await hive.auth.getLoginProviders();
const player = await hive.auth.loginAsGuest("device-id");
const applePlayer = await hive.auth.loginWithApple({
clientId: "com.example.web",
});React
import { HiveProvider, useAuth } from "@hive-ng/web-sdk/react";
function App() {
return (
<HiveProvider
config={{
gatewayUrl: "https://gateway.example.com",
projectId: "project-id",
apiKey: "api-key",
persistSession: true,
}}
>
<Login />
</HiveProvider>
);
}
function Login() {
const { ready, player, loginAsGuest } = useAuth();
if (!ready) {
return null;
}
return (
<button onClick={() => loginAsGuest("device-id")}>
{player ? player.nickname : "Login as guest"}
</button>
);
}CDN
<script src="https://cdn.jsdelivr.net/npm/@hive-ng/web-sdk"></script>
<script>
const hive = HiveNg.createHiveNg({
gatewayUrl: "https://gateway.example.com",
projectId: "project-id",
apiKey: "api-key",
});
</script>API
createHiveNg(config)hive.init()hive.auth.getLoginProviders(countryOverride?)hive.auth.loginWithGoogle(idToken)hive.auth.loginWithApple({ clientId, timeoutMs?, popupName?, popupFeatures? })hive.auth.loginAsGuest(deviceId)hive.auth.logout()hive.auth.currentPlayer()
