Skip to content
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

Improve Dolby Millicast APIs #32

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-package-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Dolby Laboratories
Copyright (c) 2024 Dolby Laboratories

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Dolby.io REST APIs Client for Python

Python wrapper for the dolby.io REST [Communications](https://docs.dolby.io/communications-apis/reference/authentication-api), [Streaming](https://docs.dolby.io/streaming-apis/reference) and [Media](https://docs.dolby.io/media-processing/reference/media-enhance-overview) APIs.
Python wrapper for the [Dolby Millicast](https://docs.dolby.io/streaming-apis/reference) and [Media](https://docs.dolby.io/media-processing/reference/media-enhance-overview) APIs.

## Build the builder

Expand Down
152 changes: 17 additions & 135 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dolby.io REST APIs Client for Python

Python wrapper for the dolby.io REST [Communications](https://docs.dolby.io/communications-apis/reference/authentication-api), [Streaming](https://docs.dolby.io/streaming-apis/reference) and [Media](https://docs.dolby.io/media-processing/reference/media-enhance-overview) APIs.
Python wrapper for the [Dolby Millicast](https://docs.dolby.io/streaming-apis/reference) and [Media](https://docs.dolby.io/media-processing/reference/media-enhance-overview) APIs.

## Install this project

Expand All @@ -16,148 +16,19 @@ Upgrade your package to the latest version:
python3 -m pip install --upgrade dolbyio-rest-apis
```

## Logging

You can change the log level by using the Python [logging](https://docs.python.org/3/library/logging.html) library.

```python
import logging

logging.basicConfig(level='DEBUG')
```

## Authentication

In order to make API calls for most operations of the **Communications APIs** and **Media APIs**, you must get an access token using this API:

```python
import asyncio
from dolbyio_rest_apis import authentication

APP_KEY = 'YOUR_APP_KEY'
APP_SECRET = 'YOUR_APP_SECRET'

loop = asyncio.get_event_loop()

task = authentication.get_api_token(APP_KEY, APP_SECRET)
at = loop.run_until_complete(task)

print(f'API Token: {at.access_token}')
```

To request a particular scope for this access token:

```python
task = authentication.get_api_token(APP_KEY, APP_SECRET, scope=['comms:*'])
at = loop.run_until_complete(task)

print(f'API Token: {at.access_token}')
print(f'Scope: {at.scope}')
```

## Communications Examples

### Get a client access token

To get an access token that will be used by the client SDK for an end user to open a session against dolby.io, use the following code:

```python
import asyncio
from dolbyio_rest_apis import authentication as auth
from dolbyio_rest_apis.communications import authentication

APP_KEY = 'YOUR_APP_KEY'
APP_SECRET = 'YOUR_APP_SECRET'

loop = asyncio.get_event_loop()

# Request an API Token
task = auth.get_api_token(APP_KEY, APP_SECRET, scope=['comms:client_access_token:create'])
api_token = loop.run_until_complete(task)

print(f'API Token: {api_token.access_token}')

# Request the Client Access Token
task = authentication.get_client_access_token_v2(api_token.access_token, ['*'])
cat = loop.run_until_complete(task)

print(f'Client Access Token: {cat.access_token}')
```

Because most of the APIs are asynchronous, you can write an async function like that:

```python
from dolbyio_rest_apis import authentication as auth
from dolbyio_rest_apis.communications import authentication

APP_KEY = 'YOUR_APP_KEY'
APP_SECRET = 'YOUR_APP_SECRET'

async def get_client_access_token():
# Request an API Token
api_token = await auth.get_api_token(APP_KEY, APP_SECRET, scope=['comms:client_access_token:create'])

# Request the Client Access Token
cat = await authentication.get_client_access_token_v2(api_token.access_token, ['*'])
print(f'Client Access Token: {cat.access_token}')

return cat.access_token

```

### Create a conference

To create a Dolby Voice conference, you first must retrieve an API Access Token, then use the following code to create the conference.

```python
import asyncio
from dolbyio_rest_apis import authentication
from dolbyio_rest_apis.communications import conference
from dolbyio_rest_apis.communications.models import Participant, Permission, VideoCodec

APP_KEY = 'YOUR_APP_KEY'
APP_SECRET = 'YOUR_APP_SECRET'

owner_id = '' # Identifier of the owner of the conference
alias = '' # Conference alias

participants = [
Participant('hostA', [Permission.JOIN, Permission.SEND_AUDIO, Permission.SEND_VIDEO], notify=True),
Participant('listener1', [Permission.JOIN], notify=False),
]

loop = asyncio.get_event_loop()

# Request an API token
task = authentication.get_api_token(APP_KEY, APP_SECRET, scope=['comms:conf:create'])
at = loop.run_until_complete(task)

# Create the conference
task = conference.create_conference(
at.access_token,
owner_id,
alias,
video_codec=VideoCodec.VP8,
participants=participants
)
conf = loop.run_until_complete(task)

print(f'Conference created: {conf.id}')
```

## Real-time Streaming Examples

### Create a publish token

```python
import asyncio
from dolbyio_rest_apis.streaming import publish_token
from dolbyio_rest_apis.streaming.models.publish_token import CreatePublishToken, CreateUpdatePublishTokenStream
from dolbyio_rest_apis.streaming.models.publish_token import CreatePublishToken, TokenStreamName

API_SECRET = '' # Retrieve your API Secret from the dashboard

create_token = CreatePublishToken('my_token')
create_token.streams.append(CreateUpdatePublishTokenStream('feed1', False))
create_token.streams.append(TokenStreamName('feed1', False))

loop = asyncio.get_event_loop()

Expand All @@ -172,12 +43,13 @@ print(token)
```python
import asyncio
from dolbyio_rest_apis.streaming import subscribe_token
from dolbyio_rest_apis.streaming.models.subscribe_token import CreateSubscribeToken, CreateUpdateSubscribeTokenStream
from dolbyio_rest_apis.streaming.models.publish_token import TokenStreamName
from dolbyio_rest_apis.streaming.models.subscribe_token import CreateSubscribeToken

API_SECRET = '' # Retrieve your API Secret from the dashboard

create_token = CreateSubscribeToken('my_token')
create_token.streams.append(CreateUpdateSubscribeTokenStream('feed1', False))
create_token.streams.append(TokenStreamName('feed1', False))

loop = asyncio.get_event_loop()

Expand All @@ -197,7 +69,7 @@ Get the App Key and Secret from the Dolby.io dashboard and use the following cod

```python
import asyncio
from dolbyio_rest_apis import authentication
from dolbyio_rest_apis.media import authentication

APP_KEY = 'YOUR_APP_KEY'
APP_SECRET = 'YOUR_APP_SECRET'
Expand Down Expand Up @@ -320,3 +192,13 @@ task = io.download_file(
)
loop.run_until_complete(task)
```

## Logging

You can change the log level by using the Python [logging](https://docs.python.org/3/library/logging.html) library.

```python
import logging

logging.basicConfig(level='DEBUG')
```
3 changes: 2 additions & 1 deletion client/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
aiohttp>=3.7.4
aiofiles>=0.7.0
aiohttp-retry>=2.4.6
certifi>=2022.12.7
certifi>=2024.7.4
dataclasses-json>=0.6.7
8 changes: 3 additions & 5 deletions client/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
license='MIT',
url='https://github.com/dolbyio/dolbyio-rest-apis-client-python',
project_urls={
'Documentation': 'https://docs.dolby.io/communications-apis/reference',
'Documentation': 'https://docs.dolby.io/streaming-apis/reference',
'Source': 'https://github.com/dolbyio/dolbyio-rest-apis-client-python',
'Bug Tracker': 'https://github.com/dolbyio/dolbyio-rest-apis-client-python/issues',
},
package_dir={'': os.path.join(current_path, 'src')},
packages=setuptools.find_packages(where=os.path.join(current_path, 'src')),
python_requires='>=3.7',
python_requires='>=3.10',
use_scm_version= {
'local_scheme': 'no-local-version',
'version_scheme': 'release-branch-semver',
Expand All @@ -43,10 +43,8 @@
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3 :: Only',
'Operating System :: OS Independent',
'Intended Audience :: Developers',
Expand Down
74 changes: 0 additions & 74 deletions client/src/dolbyio_rest_apis/authentication.py

This file was deleted.

Empty file.
Loading
Loading