Skip to content

Commit

Permalink
improve python examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarbugli committed May 9, 2024
1 parent dd0cd4d commit 9597abc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 85 deletions.
4 changes: 2 additions & 2 deletions docusaurus/video/docusaurus/docs/api/_common_/broadcast.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ call.stopHLSBroadcasting();
<TabItem value="py" label="Python">

```py
call.start_broadcasting()
call.start_hls_broadcasting()

# to end broadcasting
call.stop_broadcasting()
call.start_hls_broadcasting()
```

</TabItem>
Expand Down
2 changes: 2 additions & 0 deletions docusaurus/video/docusaurus/docs/api/_common_/rtmp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ console.log(rtmpURL, streamKey);
<TabItem value="py" label="Python">

```py
from getstream.models import UserRequest

call = client.video.call("default", uuid.uuid4())
# create the call where the RTMP will be sent to
response = call.get_or_create()
Expand Down
57 changes: 32 additions & 25 deletions docusaurus/video/docusaurus/docs/api/basics/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ await client.upsertUsers({
<TabItem value="py" label="Python">

```py
client.upsert_users(UserRequest(
id='user_id', role="user", custom={"color": "red"}, name="This is a test user",image= "link/to/profile/image",)
from getstream.models import UserRequest

client.upsert_users(
UserRequest(
id="user_id",
role="user",
custom={"color": "red"},
name="This is a test user",
image="link/to/profile/image",
)
)
```

Expand Down Expand Up @@ -104,15 +112,15 @@ client.upsert_users(UserRequest(

# or
client.update_users_partial(
users= [
{
id: 'userid',
set: {
color: 'blue',
},
unset: ['name'],
},
],
users=[
UpdateUserPartialRequest(
id="userid",
set={
"color": "blue",
},
unset=["name"],
)
],
)
```

Expand Down Expand Up @@ -145,7 +153,7 @@ Deleting a user means:
Delete has the following opitions:

| Name | Type | Description | Optional |
| ---------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
|------------------------|----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|
| `user` | Enum (soft, pruning, hard) | - Soft: marks user as deleted and retains all user data. <br /> - Pruning: marks user as deleted and nullifies user information. <br /> - Hard: deletes user completely - this requires hard option for messages and conversation as well. | Yes |
| `conversations` | Enum (soft, hard) | - Soft: marks all conversation channels as deleted (same effect as Delete Channels with 'hard' option disabled). <br /> - Hard: deletes channel and all its data completely including messages (same effect as Delete Channels with 'hard' option enabled). | Yes |
| `messages` | Enum (soft, pruning, hard) | - Soft: marks all user messages as deleted without removing any related message data. <br /> - Pruning: marks all user messages as deleted, nullifies message information and removes some message data such as reactions and flags. <br /> - Hard: deletes messages completely with all related information. | Yes |
Expand Down Expand Up @@ -176,18 +184,18 @@ client.restoreUsers({ user_ids: ['<id>'] });

```py
client.deactivate_user(
user_id= '<id>',
user_id="<id>",
)

# reactivate
client.reactivate_users(
user_ids= ['<id>'],
user_ids=["<id>"],
)

client.delete_users( user_ids= ['<id>'] )
client.delete_users(user_ids=["<id>"])

# restore
client.restore_users( user_ids= ['<id>'] )
client.restore_users(user_ids=["<id>"])
```

</TabItem>
Expand Down Expand Up @@ -226,12 +234,13 @@ def create_user_token(request):
user_id = request.user.id

# the token will be valid for 1 hour
exp = int(time.time()) + 60 * 60
exp = 3600

# Here client is Stream client and it's called with the 'user_id' and the expiration time.
token = client.create_token(user_id, expiration = exp)
token = client.create_token(user_id, expiration=exp)

# The token is then returned in the response.
return JsonResponse({'token': token})
return JsonResponse({"token": token})

```

Expand Down Expand Up @@ -261,16 +270,14 @@ client.createCallToken(userId, call_cids, exp);
<TabItem value="py" label="Python">

```py
import time

user_id = 'john'
user_id = "john"

# exp and iat are optional, token will be valid for 1 hour
exp = int(time.time()) + 60 * 60
exp = 3600

call_cids = ['default:call1', 'livestream:call2']
call_cids = ["default:call1", "livestream:call2"]

client.create_cal_token(user_id=user_id, expiration=exp,call_cids= call_cids)
client.create_call_token(user_id=user_id, expiration=exp, call_cids=call_cids)
```

</TabItem>
Expand Down
10 changes: 6 additions & 4 deletions docusaurus/video/docusaurus/docs/api/streaming/hls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const isBroadcasting = resp.call.egress.broadcasting;
<TabItem value="py" label="Python">

```py
resp = call.get()
isBroadcasting = resp.data().call.egress.broadcasting
response = call.get()
print(f"broadcasting: {response.data.call.egress.broadcasting}")
```
</TabItem>
</Tabs>
Expand Down Expand Up @@ -77,8 +77,10 @@ const URL = resp.call.egress.hls?.playlist_url;
<TabItem value="py" label="Python">
```py
resp = call.get()
URL = resp.data().call.egress.hls.playlist_url
response = call.get()

# the URL of the HLS stream
response.data.call.egress.hls.playlist_url
```
</TabItem>
</Tabs>
12 changes: 7 additions & 5 deletions docusaurus/video/docusaurus/docs/api/streaming/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ const response = await call.getOrCreate({
<TabItem value="py" label="Python">

```py
from getstream.models import CallRequest, MemberRequest

call = client.video.call('livestream', callId)
response = call.create(
data= CallRequest(
created_by_id= 'john',
# You can add multiple hosts if you want to
members= [MemberRequest( user_id= 'john', role= 'host' )],
),
data=CallRequest(
created_by_id="john",
# You can add multiple hosts if you want to
members=[MemberRequest(user_id="john", role="host")],
),
)
```

Expand Down
51 changes: 2 additions & 49 deletions docusaurus/video/docusaurus/docs/api/streaming/rtmp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ slug: /streaming/rtmp
title: RTMP input
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import RTMP from '../_common_/rtmp.mdx';

## RTMP input support overview

Expand All @@ -18,53 +17,7 @@ _Please not that this page is about publishing video/audio using RTMP, **NOT** w

This is how you can acquire the necessary information for publishing RTMP using a third-party software.

<Tabs groupId="examples">
<TabItem value="js" label="JavaScript">

```js
const resp = await call.getOrCreate({ data: { created_by_id: 'john' } });
// userId of existing user
const userId = 'jane';
await client.upsertUsers({
users: {
[userId]: {
id: userId,
},
},
});
const token = client.createToken(userId);
const rtmpURL = resp.call.ingress.rtmp.address;
const streamKey = token;

console.log(rtmpURL, streamKey);
```

</TabItem>
<TabItem value="py" label="Python">

```py
# create or get the call
response = call.create(
data=CallRequest(
created_by_id='john'
)
)

# user ID of an existing user
userId = 'jane'

# the token will be valid for 1 hour
exp = int(time.time()) + 60 * 60

token = client.create_token(userId, expiration = exp)

rtmp_url = response.data().call.ingress.rtmp.address
stream_key = token
print(rtmp_url, stream_key)
```

</TabItem>
</Tabs>
<RTMP />

The user(s) streaming from the third-party software will show up as regular users in the call.

Expand Down

0 comments on commit 9597abc

Please sign in to comment.