|
28 | 28 | from .endpoints import Endpoints
|
29 | 29 | from .session import Session
|
30 | 30 | from .archives import Archive, ArchiveList, OutputModes, StreamModes
|
| 31 | +from .render import Render |
31 | 32 | from .stream import Stream
|
32 | 33 | from .streamlist import StreamList
|
33 | 34 | from .sip_call import SipCall
|
@@ -1599,6 +1600,166 @@ def set_broadcast_layout(self, broadcast_id, layout_type, stylesheet=None, scree
|
1599 | 1600 | else:
|
1600 | 1601 | raise RequestError("OpenTok server error.", response.status_code)
|
1601 | 1602 |
|
| 1603 | + def start_render(self, session_id, opentok_token, url, max_duration=7200, resolution="1280x720", status_callback_url=None, properties: dict = None): |
| 1604 | + """ |
| 1605 | + This method starts a render for the specified session. |
| 1606 | +
|
| 1607 | + :param String 'session_id': The ID of a session (generated with the same `APIKEY` as specified in the URL) which you wish to start rendering into. |
| 1608 | + :param String 'token': A valid OpenTok token with a Publisher role and (optionally) connection data to be associated with the output stream. |
| 1609 | + :param String 'url': A publically reachable URL controlled by the customer and capable of generating the content to be rendered without user intervention. |
| 1610 | + :param Integer 'maxDuration' Optional: The maximum time allowed for the Render, in seconds. After this time, the Render will be stopped automatically, if it is still running. |
| 1611 | + :param String 'resolution' Optional: Resolution of the display area for the composition. |
| 1612 | + :param String 'statusCallbackUrl' Optional: URL of the customer service where the callbacks will be received. |
| 1613 | + :param Dictionary 'properties' Optional: Initial configuration of Publisher properties for the composed output stream. |
| 1614 | + String name Optional: The name of the composed output stream which will be published to the session. |
| 1615 | + """ |
| 1616 | + payload = { |
| 1617 | + "sessionId": session_id, |
| 1618 | + "token": opentok_token, |
| 1619 | + "url": url, |
| 1620 | + "maxDuration": max_duration, |
| 1621 | + "resolution": resolution, |
| 1622 | + "statusCallbackUrl": status_callback_url, |
| 1623 | + "properties": properties |
| 1624 | + } |
| 1625 | + |
| 1626 | + logger.debug( |
| 1627 | + "POST to %r with params %r, headers %r, proxies %r", |
| 1628 | + self.endpoints.get_render_url(), |
| 1629 | + json.dumps(payload), |
| 1630 | + self.get_json_headers(), |
| 1631 | + self.proxies, |
| 1632 | + ) |
| 1633 | + |
| 1634 | + response = requests.post( |
| 1635 | + self.endpoints.get_render_url(), |
| 1636 | + json=payload, |
| 1637 | + headers=self.get_json_headers(), |
| 1638 | + proxies=self.proxies, |
| 1639 | + timeout=self.timeout, |
| 1640 | + ) |
| 1641 | + |
| 1642 | + if response and response.status_code == 202: |
| 1643 | + return Render(self, response.json()) |
| 1644 | + elif response.status_code == 400: |
| 1645 | + """ |
| 1646 | + The HTTP response has a 400 status code in the following cases: |
| 1647 | + You do not pass in a session ID or you pass in an invalid session ID. |
| 1648 | + You specify an invalid value for input parameters. |
| 1649 | + """ |
| 1650 | + raise RequestError(response.json().get("message")) |
| 1651 | + elif response.status_code == 403: |
| 1652 | + raise AuthError("You passed in an invalid OpenTok API key or JWT token.") |
| 1653 | + else: |
| 1654 | + raise RequestError("An unexpected error occurred", response.status_code) |
| 1655 | + |
| 1656 | + |
| 1657 | + def get_render_status(self, render_id): |
| 1658 | + """ |
| 1659 | + This method allows you to see the status of a render, which can be one of the following: |
| 1660 | + ['starting', 'started', 'stopped', 'failed'] |
| 1661 | +
|
| 1662 | + :param String 'render_id': The ID of a specific render. |
| 1663 | + """ |
| 1664 | + logger.debug( |
| 1665 | + "GET to %r with headers %r, proxies %r", |
| 1666 | + self.endpoints.get_render_url(render_id=render_id), |
| 1667 | + self.get_json_headers(), |
| 1668 | + self.proxies, |
| 1669 | + ) |
| 1670 | + |
| 1671 | + response = requests.get( |
| 1672 | + self.endpoints.get_render_url(render_id=render_id), |
| 1673 | + headers=self.get_json_headers(), |
| 1674 | + proxies=self.proxies, |
| 1675 | + timeout=self.timeout, |
| 1676 | + ) |
| 1677 | + |
| 1678 | + if response.status_code == 200: |
| 1679 | + return Render(response.json()) |
| 1680 | + elif response.status_code == 400: |
| 1681 | + raise RequestError( |
| 1682 | + "Invalid request. This response may indicate that data in your request is invalid JSON. Or it may indicate that you do not pass in a session ID." |
| 1683 | + ) |
| 1684 | + elif response.status_code == 403: |
| 1685 | + raise AuthError("You passed in an invalid OpenTok API key or JWT token.") |
| 1686 | + elif response.status_code == 404: |
| 1687 | + raise NotFoundError("No render matching the specified render ID was found.") |
| 1688 | + else: |
| 1689 | + raise RequestError("An unexpected error occurred", response.status_code) |
| 1690 | + |
| 1691 | + def stop_render(self, render_id): |
| 1692 | + """ |
| 1693 | + This method stops a render. |
| 1694 | +
|
| 1695 | + :param String 'render_id': The ID of a specific render. |
| 1696 | + """ |
| 1697 | + logger.debug( |
| 1698 | + "DELETE to %r with headers %r, proxies %r", |
| 1699 | + self.endpoints.get_render_url(render_id=render_id), |
| 1700 | + self.get_headers(), |
| 1701 | + self.proxies, |
| 1702 | + ) |
| 1703 | + |
| 1704 | + response = requests.delete( |
| 1705 | + self.endpoints.get_render_url(render_id=render_id), |
| 1706 | + headers=self.get_headers(), |
| 1707 | + proxies=self.proxies, |
| 1708 | + timeout=self.timeout, |
| 1709 | + ) |
| 1710 | + |
| 1711 | + if response.status_code == 200: |
| 1712 | + return "Render has been stopped successfully." |
| 1713 | + elif response.status_code == 400: |
| 1714 | + raise RequestError( |
| 1715 | + "Invalid request. This response may indicate that data in your request is invalid JSON. Or it may indicate that you do not pass in a session ID." |
| 1716 | + ) |
| 1717 | + elif response.status_code == 403: |
| 1718 | + raise AuthError("You passed in an invalid OpenTok API key or JWT token.") |
| 1719 | + elif response.status_code == 404: |
| 1720 | + raise NotFoundError("No render matching the specified render ID was found.") |
| 1721 | + else: |
| 1722 | + raise RequestError("An unexpected error occurred", response.status_code) |
| 1723 | + |
| 1724 | + def list_renders(self, offset=0, count=50): |
| 1725 | + """ |
| 1726 | + List existing renders associated with the project's API key. |
| 1727 | +
|
| 1728 | + :param Integer 'offset' Optional: Start offset in the list of existing renders. |
| 1729 | + :param Integer 'count' Optional: Number of renders to retrieve, starting at 'offset'. |
| 1730 | + """ |
| 1731 | + |
| 1732 | + query_params = {"offset": offset, "count": count} |
| 1733 | + |
| 1734 | + logger.debug( |
| 1735 | + "GET to %r with headers %r, params %r, proxies %r", |
| 1736 | + self.endpoints.get_render_url(), |
| 1737 | + self.get_headers(), |
| 1738 | + query_params, |
| 1739 | + self.proxies, |
| 1740 | + ) |
| 1741 | + |
| 1742 | + response = requests.get( |
| 1743 | + self.endpoints.get_render_url() + "&count:", |
| 1744 | + headers=self.get_headers(), |
| 1745 | + params=query_params, |
| 1746 | + proxies=self.proxies, |
| 1747 | + timeout=self.timeout, |
| 1748 | + ) |
| 1749 | + |
| 1750 | + if response.status_code == 200: |
| 1751 | + return Render(response.json()) |
| 1752 | + elif response.status_code == 400: |
| 1753 | + raise RequestError( |
| 1754 | + "Invalid request. This response may indicate that data in your request is invalid JSON. Or it may indicate that you do not pass in a session ID." |
| 1755 | + ) |
| 1756 | + elif response.status_code == 403: |
| 1757 | + raise AuthError("You passed in an invalid OpenTok API key or JWT token.") |
| 1758 | + elif response.status_code == 404: |
| 1759 | + raise NotFoundError("No render matching the specified render ID was found.") |
| 1760 | + else: |
| 1761 | + raise RequestError("An unexpected error occurred", response.status_code) |
| 1762 | + |
1602 | 1763 | def _sign_string(self, string, secret):
|
1603 | 1764 | return hmac.new(
|
1604 | 1765 | secret.encode("utf-8"), string.encode("utf-8"), hashlib.sha1
|
|
0 commit comments