Skip to content

Commit

Permalink
Improve tunnel (#800)
Browse files Browse the repository at this point in the history
* Improve tunnel to a new version
  • Loading branch information
vicancy authored Sep 19, 2024
1 parent 87acec6 commit 618a5a2
Show file tree
Hide file tree
Showing 27 changed files with 16,001 additions and 23,302 deletions.
113 changes: 105 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ on:
- 'experimental/**'

jobs:
build:

javascript:
name: Build and Test JS code and samples
runs-on: ubuntu-latest

strategy:
Expand All @@ -30,7 +30,7 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
dotnet-version: [6.x]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand All @@ -41,13 +41,24 @@ jobs:
# See https://code.visualstudio.com/api/working-with-extensions/continuous-integration#github-actions
run: cd ./tools/vscode-azurewebpubsub && npm install && xvfb-run -a npm run test && cd ../../
if: runner.os == 'Linux'
- name: Install and Test All Samples
run: |
find ./samples/javascript ./experimental -name 'node_modules' -prune -o -name 'package.json' -print0 | while IFS= read -r -d '' file; do
dir=$(dirname "$file")
echo "Processing directory: $dir"
cd "$dir"
echo "Installing dependencies in $dir"
npm install
echo "Running tests in $dir"
npm run test
echo "Finished tests in $dir"
cd - > /dev/null
done
- run: npm install -g yarn
- run: yarn install
- run: |
cd tools/awps-tunnel/client
yarn install
yarn run build
yarn test
- run: yarn workspaces run test
- name: Setup .NET ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
Expand All @@ -56,4 +67,90 @@ jobs:

- name: Build C# samples
run: dotnet build samples/csharp/samples.sln

csharp:
name: Build and Test C#
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [6.x]
steps:
- uses: actions/checkout@v4
- name: Setup .NET ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Build C# samples
run: dotnet build samples/csharp/samples.sln

# Java Stage
java:
name: Build and Test Java
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: maven

- name: Build and Test Java Projects
run: |
find ./samples/java -name 'pom.xml' -print0 | while IFS= read -r -d '' file; do
dir=$(dirname "$file")
echo "Building and testing Java project in $dir"
cd "$dir"
mvn clean install
mvn test
cd - > /dev/null
done
# Python Stage
python:
name: Build and Test Python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies and Test Python Projects
run: |
find ./samples/python -name 'requirements.txt' -print0 | while IFS= read -r -d '' file; do
dir=$(dirname "$file")
echo "Installing dependencies for Python project in $dir"
cd "$dir"
pip install -r requirements.txt
echo "Running tests for Python project in $dir"
pytest --maxfail=0 --disable-warnings --junitxml=results.xml --ignore=node_modules --ignore=venv || true
TEST_COUNT=$(grep -o 'tests="[^"]*"' results.xml | sed 's/tests="//g' | sed 's/"//g')
FAILED_COUNT=$(grep -o 'failures="[^"]*"' results.xml | sed 's/failures="//g' | sed 's/"//g')
echo "Tests found: $TEST_COUNT"
echo "Tests failed: $FAILED_COUNT"
if [[ "$TEST_COUNT" -gt 0 && "$FAILED_COUNT" -gt 0 ]]; then
echo "Tests ran and some tests failed in $dir. Failing the job."
exit 1
elif [[ "$TEST_COUNT" -eq 0 ]]; then
echo "No tests found for $dir. Exiting successfully."
else
echo "All tests passed in $dir. Exiting successfully."
fi
cd - > /dev/null
done
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "azure-webpubsub",
"name": "azure-webpubsub-workspace",
"private": true,
"workspaces": [
"samples/javascript/**",
"sdk/**socketio**/",
"experimental/**",
"sdk/",
"tools/awps-tunnel/client/",
"tools/awps-tunnel/server/"
],
Expand Down
1 change: 0 additions & 1 deletion sdk/server-proxies/src/HttpServerProxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AbortSignal } from "@azure/abort-controller";
import { TokenCredential, AzureKeyCredential, isTokenCredential } from "@azure/core-auth";
import { AbortSignalLike } from "@azure/abort-controller";
import { parseConnectionString } from "./utils";
Expand Down
22 changes: 11 additions & 11 deletions tools/awps-tunnel/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@azure/web-pubsub-client": "^1.0.0",
"@fluentui/react": "^8.106.3",
"@fluentui/react-components": "^9.34.1",
"@fluentui/react-nav-preview": "^0.7.6",
"@microsoft/signalr": "^8.0.0",
"@monaco-editor/react": "^4.6.0",
"@popperjs/core": "2.11.8",
Expand All @@ -20,8 +21,6 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-highlight": "^0.15.0",
"react-json-editor-ajrm": "2.5.13",
"react-json-view": "^1.21.3",
"react-markdown": "^9.0.0",
"react-router-bootstrap": "^0.26.1",
"react-router-dom": "^6.3.0",
Expand Down Expand Up @@ -51,17 +50,17 @@
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/plugin-syntax-flow": "^7.14.5",
"@babel/plugin-transform-react-jsx": "^7.14.9",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^29.5.5",
"@types/jest": "^29.5.13",
"@types/jsonwebtoken": "^9.0.6",
"@types/markdown-it": "^13.0.2",
"@types/node": "^16.18.53",
"@types/react": "^18.2.22",
"@types/react-dom": "^18.2.7",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"@types/react-highlight": "^0.12.8",
"@types/react-json-editor-ajrm": "^2.5.6",
"@typescript-eslint/typescript-estree": "^6.12.0",
"ajv": "^8.11.0",
"cross-env": "^7.0.3",
Expand All @@ -71,8 +70,9 @@
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.0",
"eslint-plugin-react": "^7.30.1",
"jest": "^29.7.0",
"nan": "^2.16.0",
"ts-jest": "^29.1.1",
"ts-jest": "^29.2.5",
"typescript": "^5.1.6"
},
"overrides": {
Expand All @@ -82,9 +82,9 @@
"clean": "rimraf ./build",
"start": "cross-env REACT_APP_DATA_FETCHER=mock REACT_APP_API_VERSION=2023-07-01 react-scripts start",
"prebuild": "node scripts/downloadExamples.js",
"build": "npm run prebuild && npm run build:mock",
"build:npm": "cross-env REACT_APP_DATA_FETCHER=npm REACT_APP_API_VERSION=2023-07-01 react-scripts build",
"build:mock": "cross-env REACT_APP_DATA_FETCHER=mock REACT_APP_API_VERSION=2023-07-01 react-scripts build",
"build": "npm run build:mock",
"build:npm": "npm run prebuild && cross-env REACT_APP_DATA_FETCHER=npm REACT_APP_API_VERSION=2023-07-01 react-scripts build",
"build:mock": "npm run prebuild && cross-env REACT_APP_DATA_FETCHER=mock REACT_APP_API_VERSION=2023-07-01 react-scripts build",
"test": "cross-env CI=true REACT_APP_DATA_FETCHER=mock REACT_APP_API_VERSION=2023-07-01 react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint ./src/"
Expand Down
5 changes: 5 additions & 0 deletions tools/awps-tunnel/client/scripts/downloadExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const path = require('path');
const version = process.argv[2] || '2023-07-01';
const examplesDir = path.join(__dirname, `../public/api/${version}/examples/`);
const apiDir = path.join(__dirname, `../public/api/${version}`);
const swaggerFilePath = path.join(apiDir, "webpubsub.json");
if (fs.existsSync(swaggerFilePath)){
console.log(`Swagger file ${swaggerFilePath} exists, no need to download.`);
return;
}

if (!fs.existsSync(examplesDir)) {
fs.mkdirSync(examplesDir, { recursive: true });
Expand Down
6 changes: 3 additions & 3 deletions tools/awps-tunnel/client/src/components/CodeTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { TabValue } from "@fluentui/react-components";
// Non greedy
const regex = /(?<=^|\n)#\s+(.+)\r?\n([\s\S]+?)(?=\n# |$)/g;

const CodeTabs = () => {
const CodeTabs = ({ className }: { className?: string | undefined }) => {
const [markdownContent, setMarkdownContent] = useState("");

const [htmlSections, setHtmlSections] = useState<{ title: string; html: string }[]>([]);
Expand Down Expand Up @@ -40,15 +40,15 @@ const CodeTabs = () => {

return (
htmlSections.length > 0 && (
<div>
<div className={className}>
<TabList selectedValue={selectedValue} onTabSelect={(_, d) => setSelectedValue(d.value)}>
{htmlSections.map((section, index) => (
<Tab key={index} value={index}>
{section.title}
</Tab>
))}
</TabList>
<div className="m-2 p-2 bg-light" dangerouslySetInnerHTML={{ __html: htmlSections[selectedValue as any].html }} />
<div className="m-2 p-2 bg-light overflow-auto" dangerouslySetInnerHTML={{ __html: htmlSections[selectedValue as any].html }} />
</div>
)
);
Expand Down
1 change: 0 additions & 1 deletion tools/awps-tunnel/client/src/components/Connector.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { render } from '@testing-library/react';
import { Connector } from './Connector';
import { ConnectionStatus } from '../models';
Expand Down
2 changes: 1 addition & 1 deletion tools/awps-tunnel/client/src/components/Dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tbody tr:hover {
}

.resizablePanel {
border: 1px solid #ccc;
border-top: 1px solid #ccc;
}

.playground {
Expand Down
82 changes: 64 additions & 18 deletions tools/awps-tunnel/client/src/components/ResizablePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,84 @@
import React, { useState } from "react";
import React, { useState, useRef, useCallback } from "react";

export interface ResizablePanelProps {
left: React.ReactNode;
right: React.ReactNode;
className?: string;
initialLeftWidth?: string;
initialLeftWidth?: string; // Supports both percentage and pixel-based width
}

export function ResizablePanel({ left, right, className, initialLeftWidth = "30%" }: ResizablePanelProps) {
const [leftWidth, setLeftWidth] = useState(initialLeftWidth);
export function ResizablePanel({
left,
right,
className,
initialLeftWidth = "30%",
}: ResizablePanelProps) {
const [leftWidth, setLeftWidth] = useState<string>(initialLeftWidth);
const containerRef = useRef<HTMLDivElement>(null);
const splitterRef = useRef<HTMLDivElement>(null);
const isResizing = useRef<boolean>(false);

// Handle mouse move event to update width
const handleMouseMove = useCallback((e: MouseEvent) => {
if (isResizing.current && containerRef.current) {
const newWidth = Math.max(50, e.pageX - containerRef.current.getBoundingClientRect().left);
setLeftWidth(`${newWidth}px`);
}
}, []);

// Handle mouse up event to stop resizing
const handleMouseUp = useCallback(() => {
isResizing.current = false;
document.removeEventListener("mousemove", handleMouseMove);
document.removeEventListener("mouseup", handleMouseUp);
document.body.style.userSelect = "auto"; // Re-enable text selection
}, [handleMouseMove]);

// Handle mouse down event to start resizing
const handleMouseDown = useCallback((e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
isResizing.current = true;
document.addEventListener("mousemove", handleMouseMove);
document.addEventListener("mouseup", handleMouseUp);
document.body.style.userSelect = "none"; // Disable text selection
}, [handleMouseMove, handleMouseUp]);

const handleResize = (e: MouseEvent) => {
setLeftWidth(`${e.pageX}px`);
};

return (
<div className={`resizablePanel d-flex ${className || ""} overflow-auto`}>
<div className="d-flex flex-column overflow-auto" style={{ flex: `0 0 ${leftWidth}`, resize: "horizontal" }}>
<div
ref={containerRef}
className={`resizablePanel d-flex ${className || ""}`}
style={{ width: "100%", height: "100%", overflow: "hidden" }}
>
{/* Left Panel */}
<div
className="d-flex flex-column"
style={{ flex: `0 0 ${leftWidth}`, overflow: "auto" }}
>
{left}
</div>

{/* Splitter */}
<div
ref={splitterRef}
onMouseDown={handleMouseDown}
className="d-flex flex-column"
style={{
flex: `0 0 3px`,
backgroundColor: "#ccc",
width: "3px",
background: "linear-gradient(to right, #ccc, #eee, #ccc)",
cursor: "col-resize",
}}
onMouseDown={(e) => {
document.addEventListener("mousemove", handleResize);
document.addEventListener("mouseup", () => {
document.removeEventListener("mousemove", handleResize);
});
flexShrink: 0, // Prevent shrinking
}}
></div>
<div className="d-flex flex-column overflow-auto flex-fill">{right}</div>

{/* Right Panel */}
<div
className="d-flex flex-column flex-fill"
style={{ overflow: "auto" }}
>
{right}
</div>
</div>
);
}
Loading

0 comments on commit 618a5a2

Please sign in to comment.