-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SSE support and deprecated socket-io
- Loading branch information
1 parent
122890e
commit 93283b9
Showing
6 changed files
with
99 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Union | ||
from urllib.parse import urlencode, urljoin | ||
from sseclient import SSEClient | ||
from tagoio_sdk.common.tagoio_module import GenericModuleParams | ||
from tagoio_sdk.regions import getConnectionURI | ||
|
||
|
||
class OpenSSEWithID(GenericModuleParams): | ||
def __init__(self, channel: str, resource_id: str): | ||
super().__init__() | ||
self.channel = channel | ||
self.resource_id = resource_id | ||
|
||
|
||
class OpenSSEWithoutID(GenericModuleParams): | ||
def __init__(self, channel: str): | ||
super().__init__() | ||
self.channel = channel | ||
|
||
|
||
OpenSSEConfig = Union[OpenSSEWithID, OpenSSEWithoutID] | ||
|
||
channelsWithID = ["device_inspector", "analysis_console", "ui_dashboard"] | ||
channelsWithoutID = ["notification", "analysis_trigger", "ui"] | ||
channels = channelsWithID + channelsWithoutID | ||
|
||
|
||
def isChannelWithID(params: OpenSSEConfig) -> bool: | ||
return params.channel in channelsWithID | ||
|
||
|
||
def openSSEListening(params: OpenSSEConfig) -> SSEClient: | ||
base_url = getConnectionURI(params.region)["sse"] | ||
url = urljoin(base_url, "/events") | ||
|
||
query_params = {"token": params.token} | ||
if isChannelWithID(params): | ||
query_params["channel"] = f"{params.channel}.{params.resource_id}" | ||
else: | ||
query_params["channel"] = params.channel | ||
|
||
url += "?" + urlencode(query_params) | ||
|
||
return SSEClient(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters