-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added commands to run something when client connect/disconnect
- Added support for SELKIES_START_AFTER_CONNECT and SELKIES_START_AFTER_CONNECT variables - Added support for --start-after-connect and --start-after-disconnect start arguments - Removed duplicated base64 import in signalling_web.py
- Loading branch information
Showing
2 changed files
with
31 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
# Author: Nirbheek Chauhan <[email protected]> | ||
|
||
import os | ||
import base64 | ||
import sys | ||
import ssl | ||
import logging | ||
|
@@ -32,6 +31,7 @@ | |
import hashlib | ||
import hmac | ||
import base64 | ||
import subprocess | ||
|
||
from pathlib import Path | ||
from http import HTTPStatus | ||
|
@@ -277,6 +277,15 @@ async def cleanup_session(self, uid): | |
wso, oaddr, _, _ = self.peers[other_id] | ||
del self.peers[other_id] | ||
await wso.close() | ||
# Run application after last session disconnected | ||
try: | ||
if 'SELKIES_START_AFTER_DISCONNECT' in os.environ and len(self.sessions) == 0: | ||
if os.environ['SELKIES_START_AFTER_DISCONNECT'] != '': | ||
command = os.environ['SELKIES_START_AFTER_DISCONNECT'].split(' ') | ||
subprocess.Popen(command, stdout=subprocess.DEVNULL, | ||
stderr=subprocess.DEVNULL) | ||
except Exception as e: | ||
logger.error('Failed to run SELKIES_START_AFTER_DISCONNECT: {}'.format(e)) | ||
|
||
async def cleanup_room(self, uid, room_id): | ||
room_peers = self.rooms[room_id] | ||
|
@@ -367,6 +376,15 @@ async def connection_handler(self, ws, uid, meta=None): | |
wsc = self.peers[callee_id][0] | ||
logger.info('Session from {!r} ({!r}) to {!r} ({!r})' | ||
''.format(uid, raddr, callee_id, wsc.remote_address)) | ||
# Run application on first session connection | ||
try: | ||
if 'SELKIES_START_AFTER_CONNECT' in os.environ and len(self.sessions) == 0: | ||
if os.environ['SELKIES_START_AFTER_CONNECT'] != '': | ||
command = os.environ['SELKIES_START_AFTER_CONNECT'].split(' ') | ||
subprocess.Popen(command, stdout=subprocess.DEVNULL, | ||
stderr=subprocess.DEVNULL) | ||
except Exception as e: | ||
logger.error('Failed to run SELKIES_START_AFTER_CONNECT: {}'.format(e)) | ||
# Register session | ||
self.peers[uid][2] = peer_status = 'session' | ||
self.sessions[uid] = callee_id | ||
|