# GMetri Player

The GMetri Player is a **full-fledged Metaverse application** that can run experiences created using the GMetri editor.

The latest javascript file is hosted [here](https://s.vrgmetri.com/gm-gb-test/gmetri-player/local/web/player.bundle.js). **We recommend you to not self-host this file to receive latest updates from us.**

There are 2 simple steps to get GMetri Player running on your website.

* Drop the below script in the `<head>` section of your web-page

```html
<script type="application/javascript" 
src="https://s.vrgmetri.com/gm-gb-test/gmetri-player/local/web/player.bundle.js">
</script>
```

* Initialize the Player API by passing the JSON and options

```typescript
// usage 
const player = gmetri.player.load({
  json: {}, 
  options: { 
    htmlAnchor: document.body, 
    onSceneChange: () => {}, 
    onRuleTriggered: () => {}, 
    onViewerStateChange: () => {}, 
  } 
}).play();
```

### Player Options

```typescript
type PlayerOptions = { 
  htmlAnchor?: HTMLElement,
  onSceneChange?: () => Promise<void>,
  onRuleTriggered?: () => Promise<void>,
  onViewerStateChange?: () => Promise<void>,
};
```

1. **htmlAnchor** - Reference to the HTML element you want the player to attach to
2. **onSceneChange** - Optional callback, fired whenever a scene is changed inside the experience
3. **onRuleTriggered** - Optional callback, fired whenever a rule is triggered
4. **onViewerStateChange** - Optional callback, fired whenever the [variables](/metaverse/build/variables.md)' state changes.&#x20;

### Project JSON

The Player API accepts a [recursive tree structure](https://github.com/gmetrixr/rjson) - codenamed ***rJson***.

This JSON structure can be easily created using our [open source library](https://github.com/gmetrixr/rjson) on GitHub. Feel free to fork it!

To get started on understanding JSON structure, look at the sample jsons added in the github repo [here](https://github.com/gmetrixr/rjson/blob/main/test/r/jsons). rJson library also exports all the helper functions that you can use to create rJson structures. Have a look at the usage [here](https://github.com/gmetrixr/rjson/blob/main/test/r/1.factory.spec.ts)

There's also a codesandbox that showcases the absolute power of creating **Metaverse Apps** using the GMetri Plugin API

{% embed url="<https://r27u8.csb.app/>" %}
Codesandbox for GMetri SDK
{% endembed %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gmetri.com/metaverse/sdk/gmetri-player.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
