-
Notifications
You must be signed in to change notification settings - Fork 3
FCE-1573: Livesteaming mobile docs #117
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4d8db75
change broadcasting to livestreaming
MiloszFilimowski 8015a07
replace broadcasting with livestream
MiloszFilimowski 0bfedfc
Merge branch 'main' into mfilimowski/FCE-1573-livesteaming-mobile
PiotrWodecki e0e2445
add new words
MiloszFilimowski 193e789
Merge remote-tracking branch 'origin/mfilimowski/FCE-1573-livesteamin…
MiloszFilimowski d31ffc6
update submodule
czerwiukk f46e7e0
minor improvements
czerwiukk 601a766
link to main livestreaming doc
czerwiukk e3ae7e3
add prerequisites
czerwiukk 2ff6a3b
minor improvements
czerwiukk 1c70d62
add streaming example in react
czerwiukk 9ccdc75
fix enigmatic sentence
czerwiukk bb47253
cr improvements
czerwiukk c32144b
Merge branch 'main' into mfilimowski/FCE-1573-livesteaming-mobile
czerwiukk fcf13fb
adjust note about only 1 v/a track
czerwiukk 1127560
remove a not the best snippet
czerwiukk 88702b8
change warn to note
czerwiukk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,3 +92,6 @@ WHEP | |
| livestream | ||
| livestreaming | ||
| broadcasted | ||
| livestream | ||
| livestreamer | ||
| livestreams | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| --- | ||
| sidebar_position: 9 | ||
| title: "Livestreaming" | ||
| description: "How to use Fishjam for livestreaming" | ||
| --- | ||
|
|
||
| import Tabs from "@theme/Tabs"; | ||
| import TabItem from "@theme/TabItem"; | ||
| import ConfigurePermissions from "./_components/configure-permissions.mdx"; | ||
|
|
||
| # Livestreaming | ||
|
|
||
| This section provides examples on how to quickly set up livestreaming in React Native using Fishjam. | ||
| You can learn more about [livestreaming in Fishjam](/livestreaming) in our documentation. | ||
|
|
||
| ## How to start streaming? | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - [A room of `livestream` type](/livestreaming) | ||
| - A [peer token](/glossary#peer-token) generated for that room | ||
|
|
||
| To start streaming, simply [join the room](/react-native/connecting) and [stream as you normally would](/react-native/start-streaming). | ||
|
|
||
| :::note | ||
| Livestreaming scenario allows only one video and one audio track to be sent at a time. | ||
| Any additional tracks will be ignored and will not be available to the viewers. | ||
| ::: | ||
|
|
||
| ## How to receive the stream? | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - A peer connected and streaming in a room of `livestream` type | ||
| - A [viewer token](/livestreaming) generated for that room | ||
|
|
||
| Fishjam SDK provides a [`useLivestream`](/api/mobile/functions/useLivestream) hook to receive the broadcasted stream. | ||
| Pass the viewer token to the `connect` method of the hook to establish a connection with Fishjam. | ||
| Once the connection is established, the `LivestreamView` component will render the video stream. | ||
|
|
||
| ## Examples | ||
|
|
||
| Below are examples of how to implement the flows described above in React Native using Fishjam. | ||
|
|
||
| :::info | ||
|
|
||
| This guide assumes you already finished either the [Quick Setup](/react-native/quick-setup) or [Installation](/react-native/installation) guide. | ||
|
|
||
| ::: | ||
|
|
||
| ### Required permissions | ||
|
|
||
| <details> | ||
| <summary>Configure permissions before livestreaming</summary> | ||
|
|
||
| <ConfigurePermissions /> | ||
|
|
||
| </details> | ||
|
|
||
| ### Streamer setup example | ||
|
|
||
| Here is an example of a simple component that immediately streams the front camera: | ||
|
|
||
| ```tsx | ||
| import { useEffect } from "react"; | ||
| import { | ||
| useCamera, | ||
| useConnection, | ||
| VideoPreviewView, | ||
| } from "@fishjam-cloud/react-native-client"; | ||
|
|
||
| const ROOM_MANAGER_ID = ""; | ||
|
|
||
| export default function Streamer() { | ||
| const { prepareCamera } = useCamera(); | ||
| const { joinRoom, leaveRoom } = useConnection(); | ||
|
|
||
| useEffect(() => { | ||
| const startStreaming = async () => { | ||
| console.log("Getting room details..."); | ||
| const { url, peerToken } = await getRoomDetails( | ||
| "TestRoom", | ||
| "StreamerUserName", | ||
| ); | ||
|
|
||
| console.log("Preparing camera..."); | ||
| await prepareCamera({ cameraEnabled: true }); | ||
|
|
||
| await joinRoom({ url, peerToken }); | ||
| console.log("Streaming..."); | ||
| }; | ||
|
|
||
| startStreaming(); | ||
| return () => { | ||
| leaveRoom(); | ||
| }; | ||
| }, [prepareCamera, joinRoom, leaveRoom]); | ||
|
|
||
| return ( | ||
| <VideoPreviewView | ||
| style={{ width: "90%", aspectRatio: 1, alignSelf: "center" }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| async function getRoomDetails(roomName: string, peerName: string) { | ||
| // This will work ONLY for the Sandbox App | ||
| const response = await fetch( | ||
| `https://fishjam.io/api/v1/connect/${ROOM_MANAGER_ID}/room-manager/?roomName=${roomName}&peerName=${peerName}&roomType=livestream`, | ||
| ); | ||
| return response.json(); | ||
| } | ||
| ``` | ||
|
|
||
| ### Viewer setup example | ||
|
|
||
| Here is an example of a component that just receives a livestream. | ||
| The `LivestreamView` component will render the video stream once you connect to Fishjam using the connect method from [`useLivestream`](/api/mobile/functions/useLivestream). | ||
|
|
||
| ```tsx | ||
| import { useCallback, useEffect } from "react"; | ||
| import { View } from "react-native"; | ||
| import { | ||
| useLivestream, | ||
| LivestreamView, | ||
| } from "@fishjam-cloud/react-native-client"; | ||
|
|
||
| const YOUR_APP_ID = ""; | ||
|
|
||
| export function Receiver() { | ||
| const { connect, disconnect } = useLivestream(); | ||
|
|
||
| const handleConnect = useCallback(async () => { | ||
| try { | ||
| console.log("Getting stream details..."); | ||
| const { token } = await getViewerToken("TestRoom"); | ||
| await connect(`https://fishjam.io/api/v1/live`, token); | ||
| console.log("Receiving..."); | ||
| } catch (err) { | ||
| console.log(err); | ||
| } | ||
| }, [connect]); | ||
|
|
||
| useEffect(() => { | ||
| handleConnect(); | ||
|
|
||
| return () => { | ||
| disconnect(); | ||
| }; | ||
| }, [handleConnect, disconnect]); | ||
|
|
||
| return ( | ||
| <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}> | ||
| <LivestreamView | ||
| style={{ width: "90%", aspectRatio: 1, backgroundColor: "black" }} | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| async function getViewerToken(roomName: string) { | ||
| // This will work ONLY for the Sandbox App | ||
|
czerwiukk marked this conversation as resolved.
|
||
| // see https://fishjam.io/docs/livestreaming | ||
| const response = await fetch( | ||
| `https://fishjam.io/api/v1/connect/${YOUR_APP_ID}/room-manager/${roomName}/broadcast-viewer-token`, | ||
| ); | ||
| return response.json(); | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule mobile-client-sdk
updated
10 files
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.