Skip to content

Commit

Permalink
Merge pull request #4 from readyplayerme/feature/updates
Browse files Browse the repository at this point in the history
Removed Subscription Deleted Event
  • Loading branch information
srcnalt authored Mar 28, 2023
2 parents 603b16f + 6d1e8da commit b27888c
Show file tree
Hide file tree
Showing 5 changed files with 20,023 additions and 4,912 deletions.
78 changes: 23 additions & 55 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,46 @@
import React, { useRef } from "react";
import { WebView } from "react-native-webview";
import WebView from 'react-native-webview';

// Replace with your custom subdomain
const subdomain = "demo";

let isSubscribed = false;
let count = 0;
const correlationId = "a0bf9c2a-44d7-4882-8e72-4bc7ab73849f";

function onAvatarExported(message) {
alert(`Avatar Url = ${message.data?.url}`);
}

const View = () => {
const webview = useRef();

const subscribe = () => {
if (isSubscribed) {
return;
}
export default function App() {
const webView = useRef();

function onAvatarUrlReceived(message) {
alert(`Avatar Url = ${message.data?.url}`);
}

isSubscribed = true;
webview.current.postMessage(
function onWebViewLoaded() {
webView.current.postMessage(
JSON.stringify({
target: "readyplayerme",
type: "subscribe",
eventName: "v1.avatar.exported",
})
);
};
}

const process = (data) => {
function onMessageReceived(message) {
const data = message.nativeEvent.data;
const json = JSON.parse(data);

// Filter for only Ready Player Me Events
if (json.source !== "readyplayerme") {

if (json?.source !== 'readyplayerme') {
return;
}

if (json.eventName === "v1.avatar.exported") {
// Event called after avatar has been created and the URL generated
onAvatarExported(json);
}

if (json.eventName !== "v1.subscription.deleted") {
count++;

if (count > 4) {
webview.current.postMessage(
JSON.stringify({
target: "readyplayerme",
type: "unsubscribe",
correlationId,
})
);
}
onAvatarUrlReceived(json);
}
};
}

return (
<WebView
ref={webview}
source={{
uri: `https://${subdomain}.readyplayer.me/avatar?frameApi`,
}}
style={{ marginTop: 20 }}
onLoad={subscribe}
onMessage={(message) => process(message.nativeEvent.data)}
<WebView
ref={webView}
style={{ marginTop: 30 }}
onLoad={onWebViewLoaded}
onMessage={onMessageReceived}
source={{ uri: `https://${subdomain}.readyplayer.me/avatar?frameApi` }}
/>
);
};

export default class App extends React.Component {
render() {
return <View />;
}
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.3.0] - 2023.03.27

## Changed

- Package versions are updated.

## Removed

- Unused packages are removed.
- Subscription deleted event removed.

## [0.2.0] - 2022.03.31

## Added
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Wolf3D
Copyright (c) 2021 Ready Player Me

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit b27888c

Please sign in to comment.