-
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.
implement connecting/disconnecting from voice channel
- Loading branch information
Showing
10 changed files
with
164 additions
and
71 deletions.
There are no files selected for viewing
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
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,30 @@ | ||
from typing import Optional | ||
|
||
from httpx import AsyncClient | ||
|
||
|
||
class GoRpc: | ||
def __init__(self, rpc_addr: str): | ||
self._address = f"http://{rpc_addr}/rpc" | ||
|
||
async def create_endpoint(self, channel_id: int) -> Optional[int]: | ||
async with AsyncClient() as cl: | ||
resp = await cl.post(self._address, json={ | ||
"id": 0, "method": "Rpc.CreateApi", "params": [{"channel_id": str(channel_id)}] | ||
}) | ||
j = resp.json() | ||
if j["error"] is None: | ||
return j["result"] | ||
print(j["error"]) | ||
|
||
async def create_peer_connection(self, channel_id: int, session_id: int, offer: str) -> Optional[str]: | ||
async with AsyncClient() as cl: | ||
resp = await cl.post(self._address, json={ | ||
"id": 0, "method": "Rpc.NewPeerConnection", "params": [ | ||
{"channel_id": str(channel_id), "session_id": str(session_id), "offer": offer} | ||
] | ||
}) | ||
j = resp.json() | ||
if j["error"] is None: | ||
return j["result"] | ||
print(j["error"]) |
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
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,37 @@ | ||
""" | ||
YEPCord: Free open source selfhostable fully discord-compatible chat | ||
Copyright (C) 2022-2024 RuslanUC | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
""" | ||
from os import urandom | ||
from typing import Optional | ||
|
||
from tortoise import fields | ||
|
||
import yepcord.yepcord.models as models | ||
from ._utils import SnowflakeField, Model | ||
|
||
|
||
def gen_token(): | ||
return urandom(32).hex() | ||
|
||
|
||
class VoiceState(Model): | ||
id: int = SnowflakeField(pk=True) | ||
guild: models.Guild = fields.ForeignKeyField("models.Guild", default=None, null=True) | ||
channel: models.Channel = fields.ForeignKeyField("models.Channel") | ||
user: models.User = fields.ForeignKeyField("models.User") | ||
session_id: str = fields.CharField(max_length=64) | ||
token: Optional[str] = fields.CharField(max_length=128, default=gen_token) |