From 45094d8246d03e4d4ea2fbb849cf2e9aa0d81534 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Mon, 10 Jun 2024 14:21:39 +0200 Subject: [PATCH 1/2] Extract custom event code snippet to remove duplication --- .../docs/api/_common_/custom-events.mdx | 40 ++++++ .../docusaurus/docs/api/basics/calls.mdx | 124 ++++++------------ .../docusaurus/docs/api/webhooks/overview.mdx | 41 +----- 3 files changed, 84 insertions(+), 121 deletions(-) create mode 100644 docusaurus/video/docusaurus/docs/api/_common_/custom-events.mdx diff --git a/docusaurus/video/docusaurus/docs/api/_common_/custom-events.mdx b/docusaurus/video/docusaurus/docs/api/_common_/custom-events.mdx new file mode 100644 index 00000000..39181e04 --- /dev/null +++ b/docusaurus/video/docusaurus/docs/api/_common_/custom-events.mdx @@ -0,0 +1,40 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +```js +// send a custom event to all users watching the call +call.sendCustomEvent({ + custom: { + 'render-animation': 'balloons', + }, + user_id: 'john', +}); +``` + + + + +```py +# send a custom event to all users watching the call +call.send_call_event(user_id=user.id, custom={"render-animation": "balloons"}) +``` + + + + +```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" + }' +``` + + + diff --git a/docusaurus/video/docusaurus/docs/api/basics/calls.mdx b/docusaurus/video/docusaurus/docs/api/basics/calls.mdx index 7977268b..b8cfcba3 100644 --- a/docusaurus/video/docusaurus/docs/api/basics/calls.mdx +++ b/docusaurus/video/docusaurus/docs/api/basics/calls.mdx @@ -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 @@ -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, + ], + }, }); ``` @@ -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: - - - -```js -// the custom event can be any kind of data -await call.sendCustomEvent({ - type: 'draw', - x: 10, - y: 30, -}); -``` - - - - - -```python -# custom events can contain arbitrary data -call.send_call_event( - user_id="john", - custom={ - "type": "draw", - "x": 10, - "y": 30, - }, -) -``` - - - - - -```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 - } - } - }' -``` - - - + Sending a custom event will dispatch the `custom` WebSocket event. @@ -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, + }, + }, }); ``` @@ -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, + }, }, + }, }); ``` @@ -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, }, + }, + }, }); ``` diff --git a/docusaurus/video/docusaurus/docs/api/webhooks/overview.mdx b/docusaurus/video/docusaurus/docs/api/webhooks/overview.mdx index e06496b0..4715b980 100644 --- a/docusaurus/video/docusaurus/docs/api/webhooks/overview.mdx +++ b/docusaurus/video/docusaurus/docs/api/webhooks/overview.mdx @@ -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`. - - - -```js -// send a custom event to all users watching the call -call.sendCustomEvent({ - custom: { - 'render-animation': 'balloons', - }, - user_id: 'john', -}); -``` - - - - -```py -# send a custom event to all users watching the call -call.send_call_event(user_id=user.id, custom={"render-animation": "balloons"}) -``` - - - - -```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" - }' -``` - - - + 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. From 449cc0b6e7872e96ecf9eecb5630c04ae21e8fc9 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Mon, 10 Jun 2024 14:51:59 +0200 Subject: [PATCH 2/2] Add block user code snippets for JS and cURL --- .../docs/api/moderation/overview.mdx | 50 ++++++++++++++++--- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/docusaurus/video/docusaurus/docs/api/moderation/overview.mdx b/docusaurus/video/docusaurus/docs/api/moderation/overview.mdx index d83cb886..13872d08 100644 --- a/docusaurus/video/docusaurus/docs/api/moderation/overview.mdx +++ b/docusaurus/video/docusaurus/docs/api/moderation/overview.mdx @@ -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', }); ``` @@ -182,7 +182,7 @@ call.muteUsers({ video: true, screenshare: true, screenshare_audio: true, - muted_by_id: 'john' + muted_by_id: 'john', }); ``` @@ -326,19 +326,19 @@ Users can be banned, when doing that they are not allowed to join or create call client.banUser({ target_user_id: '', user_id: '', - reason: '' + reason: '', }); // remove the ban for a user client.unbanUser({ - targetUserId: '' + targetUserId: '', }); // ban a user for 30 minutes client.banUser({ target_user_id: '', user_id: '', - timeout: 30 + timeout: 30, }); // ban a user and all users sharing the same IP @@ -346,7 +346,7 @@ client.banUser({ target_user_id: '', user_id: '', reason: '', - ip_ban: true + ip_ban: true, }); ``` @@ -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). - + ### 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. - ```js +client.blockUsers({ + blocked_user_id: 'bob', + user_id: 'alice', +}); + +client.getBlockedUsers({ userId: 'alice' }); + +client.unblockUsers({ + blocked_user_id: 'bob', + user_id: 'alice', +}); ``` @@ -467,6 +477,30 @@ client.unblock_users(blocked_user_id=bob.id, user_id=alice.id) ```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" + }' ```