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 b6eaf51 commit dd0cd4d
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 87 deletions.
13 changes: 7 additions & 6 deletions docusaurus/video/docusaurus/docs/api/_common_/create-call.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,24 @@ call.getOrCreate({data: /* */});
<TabItem value="py" label="Python">

```py
import uuid
from getstream.models.call_request import CallRequest

call = client.video.call("default", "id")
response = call.create(
call = client.video.call("default", uuid.uuid4())
call.create(
data=CallRequest(
created_by_id="sacha",
),
)

# optionally provide additional data
response = call.create(
call.create(
data=CallRequest(
created_by_id="sacha",
# Call members need to be existing users
# note: you can add users as members to calls to support more complex permissions
members=[
MemberRequest(user_id: "john", role: "admin"),
MemberRequest(user_id: "jack"),
MemberRequest(user_id="john", role="admin"),
MemberRequest(user_id="jack"),
],
custom={"color": "blue"},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ call.updateCallMembers({
```py
# Call members need to be existing users
# You can also update the role of existing members
call.update_members(update_members=[
MemberRequest(user_id: "sara"),
MemberRequest(user_id: "emily", role: "admin")])
call.update_call_members(
update_members=[
MemberRequest(user_id="sara"),
MemberRequest(user_id="emily", role="admin"),
]
)
```

</TabItem>
Expand Down Expand Up @@ -62,11 +65,7 @@ call.updateCallMembers({
<TabItem value="py" label="Python">

```py
call.update_members(
remove_members=[
MemberRequest(user_id: 'jack', role: 'admin')
]
)
call.update_call_members(remove_members=["jack", "sara"])
```

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

```py
resp = call.get()
# user ID of an existing user
user_id = 'jane'
call = client.video.call("default", uuid.uuid4())
# create the call where the RTMP will be sent to
response = call.get_or_create()

# ensure we have a user for the host to send video via RTMP
client.upsert_users(
UserRequest(id=user_id)
UserRequest(id="tommaso-the-host")
)

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

token = client.create_token(user_id,expiration=exp)
# create a token for the user sending video, this can be used as the stream key
stream_key = client.create_token(user_id, expiration=3600)

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

Expand Down
18 changes: 10 additions & 8 deletions docusaurus/video/docusaurus/docs/api/_common_/update-call.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ call.update({ custom: { color: 'red' } });
<TabItem value="py" label="Python">

```py
from getstream.models import CallSettingsRequest

# update some custom data for this call
call.update(custom={'color': 'red'})

# update settings for this call
call.update(
settings_override=CallSettingsRequest(
audio=AudioSettingsRequest(
mic_default_on=True,
default_device="speaker",
settings_override=CallSettingsRequest(
screensharing=ScreensharingSettingsRequest(
enabled=True, access_request_enabled=True
),
),
)
)

# or to update custom data
call.update(custom= { 'color': 'red' })
```

</TabItem>
Expand Down
14 changes: 9 additions & 5 deletions docusaurus/video/docusaurus/docs/api/basics/get_started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ client.createToken(userId, exp);
<TabItem value="py" label="Python">

```py
client.upsert_users(UserRequest(
id="john", role="user", custom={"color": "red"}, name="John",image= "link/to/profile/image",)
from getstream.models import UserRequest

# ensure the user exists
client.upsert_users(
UserRequest(
id="tommaso-id", name="tommaso", role="admin", custom={"country": "NL"}
),
)

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

client.create_token(user_id = "john", expiration = exp)
# the token will be valid for 1 hour
client.create_token(user_id="tommaso-id", expiration=3600)
```

</TabItem>
Expand Down
121 changes: 105 additions & 16 deletions docusaurus/video/docusaurus/docs/api/moderation/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ call.unblockUser({ user_id: 'sara' });

```py
# Block user
call.block_user( user_id='sara' )
call.block_user(user_id='sara')

# Unblock user
call.unblock_user( user_id= 'sara' )
call.unblock_user(user_id='sara')
```

</TabItem>
Expand All @@ -66,10 +66,14 @@ call.update({
<TabItem value="py" label="Python">

```py
from getstream.models import CallSettingsRequest

call.update(
settings_override = CallSettingsRequest(
screensharing= ScreensharingSettingsRequest( enabled= True, access_request_enabled= True ),
),
settings_override=CallSettingsRequest(
screensharing=ScreensharingSettingsRequest(
enabled=True, access_request_enabled=True
),
),
)
```

Expand Down Expand Up @@ -97,8 +101,8 @@ call.muteUsers({
```py
# You can specify which kind of stream(s) to mute
call.mute_users(
mute_all_users= True,
audio=True,
mute_all_users=True,
audio=True,
)
```

Expand All @@ -125,11 +129,12 @@ call.muteUsers({

```py
call.mute_users(
user_ids= ['sara'],
audio= True,
video= True,
screenshare= True,
screenshare_audio = True,
muted_by_id=user_id,
user_ids=[alice.id, bob.id],
audio=True,
video=True,
screenshare=True,
screenshare_audio=True,
)
```

Expand Down Expand Up @@ -162,9 +167,11 @@ call.updateUserPermissions({
<TabItem value="py" label="Python">

```py
from getstream.models import OwnCapability

call.update_user_permissions(
user_id= 'sara',
grant_permissions= [OwnCapability.SEND_AUDIO.to_str()],
user_id=alice.id,
grant_permissions=[OwnCapability.SEND_AUDIO],
)
```

Expand Down Expand Up @@ -193,10 +200,92 @@ call.updateUserPermissions({
<TabItem value="py" label="Python">

```py
from getstream.models import OwnCapability

call.update_user_permissions(
user_id= 'sara',
revoke_permissions= [OwnCapability.SEND_AUDIO.to_str()],
user_id=alice.id,
revoke_permissions=[OwnCapability.SEND_AUDIO],
)
```

</TabItem>
</Tabs>

### Banning users

Users can be banned, when doing that they are not allowed to join or create calls. Banned users also cannot ring or notify other users.

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

```js
// TODO: not implemented yet
```

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

```py
# ban a user
client.ban(
target_user_id=bad_user.id,
banned_by_id=moderator.id,
reason="banned reason here",
)

# remove the ban for a user
client.unban(target_user_id=bad_user.id)

# ban a user for 30 minutes
client.ban(
target_user_id=bad_user.id,
banned_by_id=moderator.id,
timeout=30,
)

# ban a user and all users sharing the same IP
client.ban(
target_user_id=bad_user.id,
banned_by_id=moderator.id,
reason="Banned user and all users sharing the same IP for half hour",
ip_ban=True,
)
```

</TabItem>
</Tabs>

### Deactivating users

Deactivated users are no longer able to make any API call or connect to websockets (and receive updates on event of any kind).

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

```js
// TODO: not implemented yet
```

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

```py
# deactivate one user
client.deactivate_user(user_id=alice.id)

# reactivates the user
client.reactivate_user(user_id=alice.id)

# deactivates users in bulk, this is an async operation
response = client.deactivate_users(user_ids=[alice.id, bob.id])
task_id = response.data.task_id

# get information about the task
task_status = client.get_task(task_id)

# just an example, in reality it can take a few seconds for a task to be processed
if task_status.data.status == "completed":
print(task_status.data.result)
```

</TabItem>
Expand Down
Loading

0 comments on commit dd0cd4d

Please sign in to comment.