-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
47 lines (41 loc) · 1.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# IMPORTS
from dotenv import load_dotenv
from os import environ
import argparse
import asyncio
import socket
from lib.signaling_channel import SignalingChannel
from lib.webrtc_manager import WebrtcManager
from lib.webrtc_handlers.data_channel_handler import data_channel_handler
# PARSE ARGUMENTS
hostname = socket.gethostname()
parser = argparse.ArgumentParser()
parser.add_argument("--id", required=False,
default=''.join(e for e in hostname if e.isalnum())) # use id if provided, else use hostname and strip it from special characters
parser.add_argument("--dev", required=False,
action=argparse.BooleanOptionalAction, default=False)
args = parser.parse_args()
# LOAD ENVIRONMENT VARIABLES
if(args.dev):
load_dotenv('./config/dev.env')
else:
load_dotenv('./config/prod.env')
# CONSTANTS
TOKEN = environ.get('TOKEN')
SIGNALING_SERVER_URL = environ.get('SIGNALING_SERVER_URL')
PEER_ID = args.id
PEER_TYPE = "admin"
# SETUP SIGNALING CHANNEL AND WEBRTC
channel = SignalingChannel(PEER_ID, PEER_TYPE, SIGNALING_SERVER_URL, TOKEN)
webrtcOptions = {"enableDataChannel": True,
"enableStreams": True, "dataChannelHandler": data_channel_handler}
manager = WebrtcManager(PEER_ID, PEER_TYPE, channel,
webrtcOptions, verbose=True)
if __name__ == "__main__":
asyncio.run(
channel.connect()
)
'''
YOUR CODE HERE - In this file you can right the overall logic of your application
once a succesfull peer - to - peer connetion is established.
'''