
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
peerjs-py is a Python implementation of the PeerJS library, allowing peer-to-peer connections in Python applications.
To install peerjs-py, use pip:
pip install peerjs-py
First, import the necessary modules and create a Peer instance:
python
from peerjs_python import Peer, PeerOptions
peer = Peer(PeerOptions(
host='your-peerjs-server.com',
port=9000,
secure=True # Use this if your server uses HTTPS
))
@peer.on('open')
def on_open(id):
print(f"My peer ID is: {id}")
To connect to another peer and send text data:
#Establish a connection
conn = peer.connect('remote-peer-id')
@conn.on('open')
def on_open():
# Connection is now open and ready for use
conn.send('Hello, remote peer!')
@conn.on('data')
def on_data(data):
print(f"Received: {data}")
For voice or video calls, you'll need to use additional libraries like PyAudio for audio processing. Here's a basic example:
python
import pyaudio
# Initialize PyAudio
p = pyaudio.PyAudio()
# Open a call connection
call = peer.call('remote-peer-id', {'audio': True, 'video': False})
@call.on('stream')
def on_stream(stream):
# Handle the incoming audio stream
# This is a simplified example and would need more code to actually play the audio
@peer.on('call')
def on_call(call):
# Answer incoming calls automatically
call.answer({'audio': True, 'video': False})
@call.on('stream')
def on_stream(stream):
# Handle the incoming audio stream
To send files between peers:
#Sending a file
with open('file.txt', 'rb') as file:
data = file.read()
conn.send({'file': data, 'filename': 'file.txt'})
# Receiving a file
@conn.on('data')
def on_data(data):
if isinstance(data, dict) and 'file' in data:
with open(data['filename'], 'wb') as file:
file.write(data['file'])
print(f"Received file: {data['filename']}")
Always implement error handling to manage potential connection issues:
@peer.on('error')
def on_error(error):
print(f"An error occurred: {error}")
To ensure the reliability and functionality of peerjs-py, we have implemented a comprehensive testing suite. Before running the tests, please note that you must have your own PeerJS signaling server set up.
We use pytest as our testing framework. To run the tests, follow these steps:
Ensure you have pytest installed:
pip install pytest
Navigate to the project root directory.
Run the tests using pytest:
pytest
We have two types of end-to-end (e2e) tests to verify the functionality of peerjs-py in different scenarios:
Python Client to Python Client Test This test checks the communication between two Python clients using peerjs-py.
To run this test:
./e2e/run-e2e.sh
PeerJS Browser Client to Python Client Test This test verifies the compatibility between a PeerJS browser client and a Python client using peerjs-py.
To run this test:
./e2e/run-e2e-test-py.sh
By running these tests, you can verify that peerjs-py is working correctly in various scenarios and is compatible with both Python-to-Python and Browser-to-Python communications.
FAQs
A Python implementation of PeerJS
We found that peerjs-py demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.