Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Create example asset for async content streaming #583

Draft
wants to merge 32 commits into
base: async-streaming-core
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
39888b4
example asset and transform for async content streaming
cehan-Chloe Jan 16, 2025
e036e6f
async node builder test
cehan-Chloe Jan 16, 2025
529a90f
initial commit
sakuntala-motukuri Feb 2, 2025
e42efd8
dummy commit
sakuntala-motukuri Feb 3, 2025
8a810d7
update wrapper component
cehan-Chloe Jan 20, 2025
d28c65c
add transform util func to async-node-plugin
cehan-Chloe Jan 30, 2025
87611b6
chat-message-wrapper transform
cehan-Chloe Jan 30, 2025
ea73152
add missing type
cehan-Chloe Jan 30, 2025
7cb95f5
remove flatten from multinode
cehan-Chloe Jan 30, 2025
82181fb
initial commit
sakuntala-motukuri Feb 2, 2025
081938b
Initial Commit in par with the core plugin logic till date. This is s…
sakuntala-motukuri Feb 4, 2025
9dc92f2
Code cleanup
sakuntala-motukuri Feb 4, 2025
6a91b59
use collection as wrapper for transformed chat-message asset
cehan-Chloe Feb 11, 2025
e59f5de
clean up chat-message-wrapper
cehan-Chloe Feb 12, 2025
a975e41
snowflake-id
cehan-Chloe Feb 12, 2025
01bd625
move module declaration to typings
cehan-Chloe Feb 12, 2025
4a3cd46
add flatten and tests
cehan-Chloe Feb 14, 2025
7a1a667
add flatten
cehan-Chloe Feb 18, 2025
396ef20
clean up comments
cehan-Chloe Feb 18, 2025
b99b7a6
remove flatten from multi-node
cehan-Chloe Feb 18, 2025
797c1e4
remove player/react dependency for asyncNodePlugin
cehan-Chloe Feb 18, 2025
5fdb42f
initial commit
sakuntala-motukuri Feb 2, 2025
c656495
use collection as wrapper for transformed chat-message asset
cehan-Chloe Feb 11, 2025
5983dc9
clean up chat-message-wrapper
cehan-Chloe Feb 12, 2025
5642000
snowflake-id
cehan-Chloe Feb 12, 2025
1491b1f
add flatten and tests
cehan-Chloe Feb 14, 2025
50dfd7d
add flatten
cehan-Chloe Feb 18, 2025
ba19505
use collection as wrapper for transformed chat-message asset
cehan-Chloe Feb 11, 2025
37fa36f
clean up chat-message-wrapper
cehan-Chloe Feb 12, 2025
4d4e593
snowflake-id
cehan-Chloe Feb 12, 2025
9c6bc31
Initial Code Commit for android version of Streaming Player 2
sakuntala-motukuri Feb 20, 2025
87a62ff
Code cleanup
sakuntala-motukuri Feb 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions core/player/src/view/builder/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ describe("multiNode", () => {
});
});

test("async node", () => {
const result = Builder.asyncNode("1", false);
expect(result.type).toBe(NodeType.Async);
expect(result.id).toBe("1");
expect(result.flatten).toBe(false);

const result2 = Builder.asyncNode("2");
expect(result2.type).toBe(NodeType.Async);
expect(result2.id).toBe("2");
expect(result2.flatten).toBe(true);
});

test("asset wrapper", () => {
const result = Builder.assetWrapper({ id: "asset", type: "text" });

expect(result.type).toBe(NodeType.Value);
expect(result.children?.[0]?.value.type).toBe("asset");
expect(result.children?.[0]?.value.value.id).toBe("asset");
});

test("asset wrapper", () => {
const result = Builder.assetWrapper({ id: "asset", type: "text" });

expect(result.type).toBe(NodeType.Value);
expect(result.children?.[0]?.value.type).toBe("asset");
expect(result.children?.[0]?.value.value.id).toBe("asset");
});

describe("addChild", () => {
test("sets the parent on the child node", () => {
const asset = Builder.asset({ id: "asset", type: "text" });
Expand Down
29 changes: 28 additions & 1 deletion core/player/src/view/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export class Builder {
};
}

static assetWrapper<T extends AnyAssetType>(value: T): Node.Value {
const asset = Builder.asset(value);
const valueNode = Builder.value();
Builder.addChild(valueNode, "asset", asset);
return valueNode;
}

/**
* Creates a value node
*
Expand All @@ -36,11 +43,12 @@ export class Builder {
* @param values - the value or applicability nodes to put in the multinode
*/
static multiNode(
...values: (Node.Value | Node.Applicability)[]
...values: (Node.Value | Node.Applicability | Node.Asset | Node.Async)[]
): Node.MultiNode {
const m: Node.MultiNode = {
type: NodeType.MultiNode,
override: true,
flatten: true,
values,
};

Expand All @@ -52,6 +60,25 @@ export class Builder {
return m;
}

/**
* Creates an async node
*
* @param id - the id of async node. It should be identical for each async node
*/
static asyncNode(id: string, flatten = true): Node.Async {
return {
id,
type: NodeType.Async,
flatten: flatten,
value: {
type: NodeType.Value,
value: {
id,
},
},
};
}

/**
* Adds a child node to a node
*
Expand Down
6 changes: 6 additions & 0 deletions core/player/src/view/parser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export declare namespace Node {

/** A list of values that comprise this node */
values: Array<Node>;

flatten?: boolean;
}

export interface Switch extends Base<NodeType.Switch> {
Expand All @@ -116,6 +118,10 @@ export declare namespace Node {
id: string;
/** The value representing the node */
value: Node;
/**
* Should this list be flattened in resolver
*/
flatten?: boolean;
}

export interface PluginOptions {
Expand Down
29 changes: 26 additions & 3 deletions core/player/src/view/resolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { DependencyModel, withParser } from "../../data";
import type { Logger } from "../../logger";
import type { Node } from "../parser";
import { NodeType } from "../parser";
import { caresAboutDataChanges, toNodeResolveOptions } from "./utils";
import {
caresAboutDataChanges,
toNodeResolveOptions,
unpackAndPush,
} from "./utils";
import type { Resolve } from "./types";
import { getNodeID } from "../parser/utils";

Expand Down Expand Up @@ -163,7 +167,6 @@ export class Resolver {
);
this.resolveCache = resolveCache;
this.hooks.afterUpdate.call(updated.value);

return updated.value;
}

Expand Down Expand Up @@ -408,7 +411,27 @@ export class Resolver {
);

if (mTree.value !== undefined && mTree.value !== null) {
childValue.push(mTree.value);
if (
mValue.type === NodeType.Async &&
mValue.flatten &&
Array.isArray(mTree.value)
) {
if (Array.isArray(mTree.value)) {
mTree.value.forEach((v: any) => {
unpackAndPush(v, childValue);
});
}
} else if (
mValue.type === NodeType.Async &&
mValue.flatten &&
Array.isArray(mTree.value.asset.values)
) {
mTree.value.asset.values.forEach((v: any) => {
unpackAndPush(v, childValue);
});
} else {
childValue.push(mTree.value);
}
}

mTree.dependencies.forEach((bindingDep) =>
Expand Down
9 changes: 9 additions & 0 deletions docs/storybook/src/reference-assets/ChatMessage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as ChatMessageStories from "./ChatMessage.stories";

# ChatMessage Asset

The `ChatMessage` asset is used as an example of async node.

## Basic Use Case

The example below shows the basic usage of async node. Transform the `ChatMessage` asset and render the `text` asset with given value
14 changes: 14 additions & 0 deletions docs/storybook/src/reference-assets/ChatMessage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { PlayerStory } from "@player-ui/storybook";
import { Meta } from "@storybook/react";

const meta: Meta = {
title: "Reference Assets/ChatMessage",
};

export default meta;

export const Basic = () => (
<PlayerStory
flow={() => import("@player-ui/mocks/chat-message/chat-message-basic.json")}
/>
);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"seamless-scroll-polyfill": "^2.3.4",
"sharp": "^0.33.5",
"signale": "^1.4.0",
"snowflake-id": "^1.0.0",
"sorted-array": "^2.0.4",
"source-map-js": "^1.0.2",
"starlight-package-managers": "^0.7.0",
Expand Down
5 changes: 5 additions & 0 deletions plugins/async-node/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ js_pipeline(
native_bundle = "AsyncNodePlugin",
peer_deps = [
":node_modules/@player-ui/player",
"//:node_modules/react",
"//:node_modules/@types/react",
],
deps = [
"//:node_modules/queue-microtask",
"//:node_modules/tapable-ts",
"//:node_modules/timm",
],
test_deps = [
":node_modules/@player-ui/reference-assets-plugin",
]
)
3 changes: 2 additions & 1 deletion plugins/async-node/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.0-PLACEHOLDER",
"main": "src/index.ts",
"peerDependencies": {
"@player-ui/player": "workspace:*"
"@player-ui/player": "workspace:*",
"@player-ui/react": "workspace:*"
}
}

Loading