Skip to content

Commit

Permalink
User blocking js (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz authored Jun 28, 2024
2 parents f4f30fe + 449cc0b commit 21360a3
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 129 deletions.
40 changes: 40 additions & 0 deletions docusaurus/video/docusaurus/docs/api/_common_/custom-events.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

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

```js
// send a custom event to all users watching the call
call.sendCustomEvent({
custom: {
'render-animation': 'balloons',
},
user_id: 'john',
});
```

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

```py
# send a custom event to all users watching the call
call.send_call_event(user_id=user.id, custom={"render-animation": "balloons"})
```

</TabItem>
<TabItem value="curl" label="cURL">

```bash
curl -X POST https://video.stream-io-api.com/api/v2/video/call/${CALL_TYPE}/${CALL_ID}/event?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H 'Content-Type: application/json' \
-d '{
"custom": {"render-animation": "balloons"},
"user_id": "john"
}'
```

</TabItem>
</Tabs>
124 changes: 42 additions & 82 deletions docusaurus/video/docusaurus/docs/api/basics/calls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import CallSort from '../../../shared/video/_call-sort-fields.mdx';
import CallMemberSort from '../../../shared/video/_call-member-sort-fields.mdx';
import OpenApiModels from '../_common_/OpenApiModels';
import CallTypesSum from '../_common_/call-types-overview.mdx';
import CustomEvents from '../_common_/custom-events.mdx';

## Creating calls

Expand Down Expand Up @@ -180,7 +181,15 @@ if (!callMemberGrants.includes(VideoOwnCapability.JOIN_CALL)) {

// Update the call type with the changes
await client.video.updateCallType(callTypeName, {
grants: { user: [], call_member: [VideoOwnCapability.JOIN_CALL, VideoOwnCapability.GET_CALL, VideoOwnCapability.SEND_AUDIO, VideoOwnCapability.JOIN_CALL] },
grants: {
user: [],
call_member: [
VideoOwnCapability.JOIN_CALL,
VideoOwnCapability.GET_CALL,
VideoOwnCapability.SEND_AUDIO,
VideoOwnCapability.JOIN_CALL,
],
},
});
```

Expand Down Expand Up @@ -594,56 +603,7 @@ curl -X POST "https://video.stream-io-api.com/api/v2/video/call/members?api_key=

It's possible to send any custom event for a call:

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

```js
// the custom event can be any kind of data
await call.sendCustomEvent({
type: 'draw',
x: 10,
y: 30,
});
```

</TabItem>

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

```python
# custom events can contain arbitrary data
call.send_call_event(
user_id="john",
custom={
"type": "draw",
"x": 10,
"y": 30,
},
)
```

</TabItem>

<TabItem value="curl" label="cURL">

```bash
curl -X POST "https://video.stream-io-api.com/api/v2/video/call/${CALL_TYPE}/${CALL_ID}/event?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{
"event": {
"custom": {
"type": "draw",
"x": 10,
"y": 30
}
}
}'
```

</TabItem>
</Tabs>
<CustomEvents />

Sending a custom event will dispatch the `custom` WebSocket event.

Expand Down Expand Up @@ -719,22 +679,22 @@ You can configure all calls to have a default max duration, this can be done fro

```js
await client.video.updateCallType({
name: 'default',
settings: {
limits: {
max_duration_seconds: 3600
}
}
name: 'default',
settings: {
limits: {
max_duration_seconds: 3600,
},
},
});

// Disable the default session timer
await client.video.updateCallType({
name: 'default',
settings: {
limits: {
max_duration_seconds: 0
}
}
name: 'default',
settings: {
limits: {
max_duration_seconds: 0,
},
},
});
```

Expand Down Expand Up @@ -810,14 +770,14 @@ It is possible to create calls with a different max duration than the default de
```js
// or call.create
await client.call('default', 'test-outgoing-call').getOrCreate({
data: {
created_by_id: 'john',
settings_override: {
limits: {
max_duration_seconds: 3600,
},
},
data: {
created_by_id: 'john',
settings_override: {
limits: {
max_duration_seconds: 3600,
},
},
},
});
```

Expand Down Expand Up @@ -876,24 +836,24 @@ It is possible to update a call and extend the session time. In that case a `cal
```js
// Update the call with session timer
await client.call.update({
data: {
settings_override: {
limits: {
max_duration_seconds: call.settings.limits.max_duration_seconds + 300,
},
},
data: {
settings_override: {
limits: {
max_duration_seconds: call.settings.limits.max_duration_seconds + 300,
},
},
},
});

// Disable the session timer
await client.call.update({
data: {
settings_override: {
limits: {
max_duration_seconds: 0,
},
},
data: {
settings_override: {
limits: {
max_duration_seconds: 0,
},
},
},
});
```

Expand Down
50 changes: 42 additions & 8 deletions docusaurus/video/docusaurus/docs/api/moderation/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ You can also mute every other participant’s video or audio.
call.muteUsers({
mute_all_users: true,
audio: true,
muted_by_id: 'john'
muted_by_id: 'john',
});
```

Expand Down Expand Up @@ -182,7 +182,7 @@ call.muteUsers({
video: true,
screenshare: true,
screenshare_audio: true,
muted_by_id: 'john'
muted_by_id: 'john',
});
```

Expand Down Expand Up @@ -326,27 +326,27 @@ Users can be banned, when doing that they are not allowed to join or create call
client.banUser({
target_user_id: '<bad user id>',
user_id: '<moderator id>',
reason: '<reason>'
reason: '<reason>',
});

// remove the ban for a user
client.unbanUser({
targetUserId: '<user id>'
targetUserId: '<user id>',
});

// ban a user for 30 minutes
client.banUser({
target_user_id: '<bad user id>',
user_id: '<moderator id>',
timeout: 30
timeout: 30,
});

// ban a user and all users sharing the same IP
client.banUser({
target_user_id: '<bad user id>',
user_id: '<moderator id>',
reason: '<reason>',
ip_ban: true
ip_ban: true,
});
```

Expand Down Expand Up @@ -435,17 +435,27 @@ curl -X POST https://video.stream-io-api.com/api/v2/moderation/ban?api_key=${API

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

<DeactivateReactivate/>
<DeactivateReactivate />

### User blocking

Users can block other users using the API, when a user blocks another it will no longer receive ringing calls or notification from the blocked user.


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

```js
client.blockUsers({
blocked_user_id: 'bob',
user_id: 'alice',
});

client.getBlockedUsers({ userId: 'alice' });

client.unblockUsers({
blocked_user_id: 'bob',
user_id: 'alice',
});
```

</TabItem>
Expand All @@ -467,6 +477,30 @@ client.unblock_users(blocked_user_id=bob.id, user_id=alice.id)
<TabItem value="curl" label="cURL">

```bash
curl -X POST https://video.stream-io-api.com/api/v2/users/block?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H 'Content-Type: application/json' \
-d '{
"blocked_user_id": "bob",
"user_id": "alice"
}'

USER_ID='alice';
ENCODED_USER_ID=$(echo ${USER_ID} | perl -MURI::Escape -lne 'print uri_escape($_)')

curl -X GET "https://video.stream-io-api.com/api/v2/users/block?api_key=${API_KEY}&user_id=${ENCODED_USER_ID}" \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt"

curl -X POST https://video.stream-io-api.com/api/v2/users/unblock?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H 'Content-Type: application/json' \
-d '{
"blocked_user_id": "bob",
"user_id": "alice"
}'
```

</TabItem>
Expand Down
41 changes: 2 additions & 39 deletions docusaurus/video/docusaurus/docs/api/webhooks/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,14 @@ slug: /webhooks/overview
title: Overview
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import CustomEvents from '../_common_/custom-events.mdx';

## Custom events

You can send custom events to all users watching a call, events can be send client-side or server-side. It is not necessary for users to be part the call, you call objects can be "watched" before joining as well.
Client-side you can observe calls and receive events by passing the `watch:true` parameter to any of these endpoints: `GetCall`, `QueryCalls`, `JoinCall`.

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

```js
// send a custom event to all users watching the call
call.sendCustomEvent({
custom: {
'render-animation': 'balloons',
},
user_id: 'john',
});
```

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

```py
# send a custom event to all users watching the call
call.send_call_event(user_id=user.id, custom={"render-animation": "balloons"})
```

</TabItem>
<TabItem value="curl" label="cURL">

```bash
curl -X POST https://video.stream-io-api.com/api/v2/video/call/${CALL_TYPE}/${CALL_ID}/event?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H 'Content-Type: application/json' \
-d '{
"custom": {"render-animation": "balloons"},
"user_id": "john"
}'
```

</TabItem>
</Tabs>
<CustomEvents />

You can configure your Stream app to send events to your HTTP/webhook and/or to your AWS SQS queue. Webhooks are usually
the simplest way to receive events from your app and to perform additional action based on what happens to your application.
Expand Down

0 comments on commit 21360a3

Please sign in to comment.