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

In the examples, add a helper function to generate a random user identity #691

Merged
merged 5 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/tame-nails-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/component-example-next": patch
---

Add helper function to generate random user identity
6 changes: 6 additions & 0 deletions examples/nextjs/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* A simple helper function to generate a random user identity.
*/
export function generateRandomUserId() {
return `test-identity-${String(Math.random() * 100_000).slice(0, 5)}` as const;
}
3 changes: 2 additions & 1 deletion examples/nextjs/pages/audio-only.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { AudioConference, LiveKitRoom, useToken } from '@livekit/components-react';
import type { NextPage } from 'next';
import { generateRandomUserId } from '../lib/helper';

const AudioExample: NextPage = () => {
const params = typeof window !== 'undefined' ? new URLSearchParams(location.search) : null;
const roomName = params?.get('room') ?? 'test-room';
const userIdentity = params?.get('user') ?? 'test-identity';
const userIdentity = params?.get('user') ?? generateRandomUserId();

const token = useToken(process.env.NEXT_PUBLIC_LK_TOKEN_ENDPOINT, roomName, {
userInfo: {
Expand Down
3 changes: 2 additions & 1 deletion examples/nextjs/pages/clubhouse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
import styles from '../styles/Clubhouse.module.scss';
import { Track } from 'livekit-client';
import { useMemo, useState } from 'react';
import { generateRandomUserId } from '../lib/helper';

const Clubhouse = () => {
const params = typeof window !== 'undefined' ? new URLSearchParams(location.search) : null;
const roomName = params?.get('room') ?? 'test-room';
const userIdentity = params?.get('user') ?? 'test-identity';
const userIdentity = params?.get('user') ?? generateRandomUserId();

const token = useToken(process.env.NEXT_PUBLIC_LK_TOKEN_ENDPOINT, roomName, {
userInfo: {
Expand Down
3 changes: 2 additions & 1 deletion examples/nextjs/pages/customize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import myStyles from '../styles/Customize.module.css';
import type { NextPage } from 'next';
import { HTMLAttributes, useState } from 'react';
import { isTrackReference } from '@livekit/components-core';
import { generateRandomUserId } from '../lib/helper';

const CustomizeExample: NextPage = () => {
const params = typeof window !== 'undefined' ? new URLSearchParams(location.search) : null;
const roomName = params?.get('room') ?? 'test-room';
const userIdentity = params?.get('user') ?? 'test-identity';
const userIdentity = params?.get('user') ?? generateRandomUserId();
const token = useToken(process.env.NEXT_PUBLIC_LK_TOKEN_ENDPOINT, roomName, {
userInfo: {
identity: userIdentity,
Expand Down
3 changes: 2 additions & 1 deletion examples/nextjs/pages/e2ee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { LiveKitRoom, useToken, VideoConference } from '@livekit/components-reac
import type { NextPage } from 'next';
import * as React from 'react';
import { Room, ExternalE2EEKeyProvider } from 'livekit-client';
import { generateRandomUserId } from '../lib/helper';

const E2EEExample: NextPage = () => {
const params = typeof window !== 'undefined' ? new URLSearchParams(location.search) : null;
const roomName = params?.get('room') ?? 'test-room';
const userIdentity = params?.get('user') ?? 'test-identity';
const userIdentity = params?.get('user') ?? generateRandomUserId();
setLogLevel('warn', { liveKitClientLogLevel: 'debug' });

const token = useToken(process.env.NEXT_PUBLIC_LK_TOKEN_ENDPOINT, roomName, {
Expand Down
3 changes: 2 additions & 1 deletion examples/nextjs/pages/minimal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { setLogLevel } from '@livekit/components-core';
import { LiveKitRoom, useToken, VideoConference } from '@livekit/components-react';
import { RoomConnectOptions } from 'livekit-client';
import type { NextPage } from 'next';
import { generateRandomUserId } from '../lib/helper';

const MinimalExample: NextPage = () => {
const params = typeof window !== 'undefined' ? new URLSearchParams(location.search) : null;
const roomName = params?.get('room') ?? 'test-room';
const userIdentity = params?.get('user') ?? 'test-identity';
const userIdentity = params?.get('user') ?? generateRandomUserId();
setLogLevel('info', { liveKitClientLogLevel: 'warn' });

const token = useToken(process.env.NEXT_PUBLIC_LK_TOKEN_ENDPOINT, roomName, {
Expand Down
3 changes: 2 additions & 1 deletion examples/nextjs/pages/simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import { Track } from 'livekit-client';
import type { NextPage } from 'next';
import { useState } from 'react';
import styles from '../styles/Simple.module.css';
import { generateRandomUserId } from '../lib/helper';

const SimpleExample: NextPage = () => {
const params = typeof window !== 'undefined' ? new URLSearchParams(location.search) : null;
const roomName = params?.get('room') ?? 'test-room';
const userIdentity = params?.get('user') ?? 'test-identity';
const userIdentity = params?.get('user') ?? generateRandomUserId();
const [connect, setConnect] = useState(false);
const [isConnected, setIsConnected] = useState(false);

Expand Down
Loading