-
Notifications
You must be signed in to change notification settings - Fork 7
/
eg_videocall_in.py
76 lines (57 loc) · 2.02 KB
/
eg_videocall_in.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import asyncio
import logging
from janus_client import JanusSession, JanusVideoCallPlugin
from aiortc.contrib.media import MediaPlayer, MediaRecorder
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
logger = logging.getLogger()
async def on_incoming_call(plugin: JanusVideoCallPlugin, jsep: dict):
# self.__player = MediaPlayer("./Into.the.Wild.2007.mp4")
player = MediaPlayer(
"http://download.tsi.telecom-paristech.fr/gpac/dataset/dash/uhd/mux_sources/hevcds_720p30_2M.mp4"
)
recorder = MediaRecorder("./videocall_record_in.mp4")
pc = await plugin.create_pc(
player=player,
recorder=recorder,
jsep=jsep,
)
await pc.setLocalDescription(await pc.createAnswer())
jsep = {
"sdp": pc.localDescription.sdp,
"trickle": False,
"type": pc.localDescription.type,
}
await plugin.accept(jsep=jsep, pc=pc, player=player, recorder=recorder)
async def main():
# Create session
session = JanusSession(
base_url="wss://janusmy.josephgetmyip.com/janusbasews/janus",
)
# Create plugin
plugin_handle = JanusVideoCallPlugin()
# Attach to Janus session
await plugin_handle.attach(session=session)
logger.info("plugin created")
# username = "testusername"
username_in = "testusernamein"
plugin_handle.on_incoming_call = on_incoming_call
result = await plugin_handle.register(username=username_in)
logger.info(result)
# result = await plugin_handle.call(
# username=username, player=player, recorder=recorder
# )
# logger.info(result)
if result:
await asyncio.sleep(60)
result = await plugin_handle.hangup()
logger.info(result)
# Destroy plugin
await plugin_handle.destroy()
# Destroy session
await session.destroy()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass