Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Commit

Permalink
feat: Beta 2!
Browse files Browse the repository at this point in the history
  • Loading branch information
Mafrans committed Aug 2, 2021
1 parent 39a52b3 commit 9537017
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 66 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Stadia+ Extension [Beta]",
"short_name": "Stadia+",
"version": "3.0.0.1",
"version": "3.0.0.2",
"author": "Malte Klüft (Mafrans)",
"description": "Extends Google's Stadia gaming platform with various network features, such as statistics and achievement-tracking.",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAj4rm88698t+T5Pe5jWP8edM6wPBErxwCu0k3Ona/Xc3lt3NJpvW5dabUdcpP3MYBjMQ41V/iq4Q64rObL9csaruxP4Ex3S8SaxBc/sDBxAUjRdYebF76t+APSeTRDs0WiKJgjUoEGBlOtSqffVYO7wpLr/IWUn9z1PfkaV5LY5jrlHJ4o0HUOoVW5v2gTUZV143hdOXQgMH9IFf1MppMzg0m7AVq+8j7L7O5334T0tKzhb2sd9uHp74jv2jTWBK1ykkoDt4ST18ZC6zdXH0/4rI3cJ/r0YlganD6wfNvJTWJ3WMCrvR/7S//qBr9iNrD65BQDFln90JPEeBScjtd8wIDAQAB",
Expand Down
6 changes: 3 additions & 3 deletions modules/main/src/StadiaGameDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export namespace StadiaGameDB {
let imgName = /images\/posters\/([a-z0-9_.-]+).png/g.exec(entry[0])?.[1];
if (imgName === undefined) imgName = '';

games[uuid] = {
StadiaGameDB.games[uuid] = {
uuid,
storeId: /https:\/\/stadia.google.com\/store\/details\/([0-9a-z/]+)/g.exec(entry[0])?.[1],
img: `https://stadiagamedb.com/images/posters/webp/square/${imgName}.webp`,
Expand All @@ -35,8 +35,8 @@ export namespace StadiaGameDB {
}

export function random(): Game {
return games[
Object.keys(games)[Math.floor(Math.random() * Object.keys(games).length)]
return StadiaGameDB.games[
Object.keys(StadiaGameDB.games)[Math.floor(Math.random() * Object.keys(StadiaGameDB.games).length)]
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import style from './game-monitor-component.css';
import classNames from 'classnames';
import { stateStore } from '../../state/StateStore';
import { observer } from 'mobx-react';
import Logger from '../../../../shared/Logger';

export type GameMonitorItem = {
name: string
Expand All @@ -39,7 +40,7 @@ const GameMonitor = observer((props: GameMonitorProps) => {
const isCapturing = useRef<boolean>();

const [items, setItems] = useState<GameMonitorItem[]>([]);
const [enabled, setEnabled] = useState<boolean>();
const [enabled, setEnabled] = useState<boolean>(false);
let [itemMeta, setItemMeta] = useState<GameMonitorItemMeta>({});
let [sidebarOpen, setSidebarOpen] = useState<boolean>();

Expand Down Expand Up @@ -74,57 +75,75 @@ const GameMonitor = observer((props: GameMonitorProps) => {
}, [page]);

const onMessageCapture = (event: MessageEvent) => {
if (event.data.source === 'StadiaPlusNetworkMonitor' && (!sidebarOpen || items.length === 0)) {
const statArray: [string, any] = event.data.stats[1];
const ICECandidatePair = RTCStatistics.RTCStatistic.from<RTCStatistics.RTCIceCandidatePair>(
statArray,
id => id.startsWith('RTCIceCandidatePair')
);

if (!ICECandidatePair) {
return;
}
try {
if (event.data.source === 'StadiaPlusNetworkMonitor' && (!sidebarOpen || items.length === 0)) {
const statArray: [string, any] = event.data.stats[1];
const ICECandidatePair = RTCStatistics.RTCStatistic.from<RTCStatistics.RTCIceCandidatePair>(
statArray,
id => id.startsWith('RTCIceCandidatePair')
);

if (!ICECandidatePair) {
return;
}

const { videoStream, videoCodec, audioCodec } = getStream(statArray);
const { bytesReceived, currentRoundTripTime } = ICECandidatePair;
const bytesPerSecond = (bytesReceived ?? 0) - lastBytesReceived.current;

// TODO: Is it possible to move into a fined format. perhaps a class?
let newItems = [
{
name: 'Latency',
value: `${Math.round(currentRoundTripTime! * 1000)} ms`,
id: 'latency',
},
{
name: 'Resolution',
value: `${videoStream?.frameWidth ?? '?'}x${videoStream?.frameHeight ?? '?'}`,
id: 'resolution',
},
{
name: 'Bytes Received',
value: `${formatBytes(ICECandidatePair.bytesReceived!)}`,
id: 'bytes-received',
},
{
name: 'Video Codec',
value: `${videoCodec?.mimeType?.split('/')?.[1] ?? 'unknown'} (${videoStream?.decoderImplementation === 'ExternalDecoder' ? 'hardware' : 'software'})`,
id: 'video-codec',
},
{
name: 'Audio Codec',
value: `${audioCodec?.mimeType?.split('/')?.[1] ?? 'unknown'}`,
id: 'audio-codec',
},
{
name: 'Bytes/s',
value: `${formatBytes(bytesPerSecond)}/s`,
id: 'bytes-per-second',
},
] as GameMonitorItem[];

lastBytesReceived.current = bytesReceived ?? 0;
setItems(newItems);
const { videoStream, videoCodec, audioCodec } = getStream(statArray);
const { bytesReceived, currentRoundTripTime } = ICECandidatePair;
const bytesPerSecond = (bytesReceived ?? 0) - lastBytesReceived.current;

// TODO: Is it possible to move into a fined format. perhaps a class?
let newItems = [
{
name: 'Latency',
value: `${Math.round(currentRoundTripTime! * 1000)} ms`,
id: 'latency',
},
{
name: 'Resolution',
value: `${videoStream?.frameWidth ?? '?'}x${videoStream?.frameHeight ?? '?'}`,
id: 'resolution',
},
{
name: 'Bytes Received',
value: `${formatBytes(ICECandidatePair.bytesReceived!)}`,
id: 'bytes-received',
},
{
name: 'Video Codec',
value: `${videoCodec?.mimeType?.split('/')?.[1] ?? 'unknown'} (${videoStream?.decoderImplementation === 'ExternalDecoder' ? 'hardware' : 'software'})`,
id: 'video-codec',
},
{
name: 'Audio Codec',
value: `${audioCodec?.mimeType?.split('/')?.[1] ?? 'unknown'}`,
id: 'audio-codec',
},
{
name: 'Bytes/s',
value: `${formatBytes(bytesPerSecond)}/s`,
id: 'bytes-per-second',
},
] as GameMonitorItem[];

if (newItems.length > Object.keys(itemMeta).length) {
const newItemMeta = itemMeta;
newItems.forEach(item => {
newItemMeta[item.id] = {
visible: true,
index: Object.keys(newItemMeta).length
}
})
setItemMeta(newItemMeta);
}

lastBytesReceived.current = bytesReceived ?? 0;
setItems(newItems);
}
}
catch (e) {
if (lastBytesReceived.current > 0) {
Logger.error(e);
}
}
}

Expand All @@ -133,14 +152,6 @@ const GameMonitor = observer((props: GameMonitorProps) => {
return;
}

const newItemMeta = itemMeta ?? {};
if (!itemMeta.hasOwnProperty(id)) {
newItemMeta[id] = {
visible: true,
index: 0,
};
}

// Reorder other items to match
Object.keys(itemMeta).forEach(key => {
if (!itemMeta?.[key]) {
Expand Down
5 changes: 3 additions & 2 deletions modules/main/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ document.addEventListener('DOMContentLoaded', async () => {
const RootComponent = observer(() =>
<>
<ResolutionComponent />
<InitLibraryComponent />
{ /* <InitLibraryComponent /> */ }
<CodecComponent />
<ResolutionComponent />
<InGameSyncComponent />
Expand All @@ -51,11 +51,12 @@ document.addEventListener('DOMContentLoaded', async () => {

const mutationObserver = new MutationObserver(mutations => {
mutations.forEach(mutation => {
console.log(location.pathname);
if(mutation.addedNodes.length) {
setRenderer(mutation.addedNodes.item(0) as HTMLElement);
Logger.debug('Render update', mutation.addedNodes.item(0));
}
setPage(findPage(location.pathname));
Logger.debug('Navigated to', location.pathname);
});
});

Expand Down
1 change: 0 additions & 1 deletion modules/shared/models/DBModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export namespace DBModel {

export function getGame(data: string, gameId: string): DBModel.Game {
const gameData = getGameData(data);
console.log(gameData);
return {
name: gameData[0][1],
image: gameData[9][2][15][1][0][1],
Expand Down

0 comments on commit 9537017

Please sign in to comment.