Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Janus SDK #347

Closed
wants to merge 16 commits into from
Closed

Implement Janus SDK #347

wants to merge 16 commits into from

Conversation

farhat-ha
Copy link
Collaborator

@farhat-ha farhat-ha commented Mar 11, 2024

https://telnyx.atlassian.net/browse/TELAPPS-4802

This PR is easier to review by commit
Describe your changes

Impement janus client

📝 To Do

  • All linters pass
  • All tests pass
  • Change documentation based on my changes

✋ Manual testing

  1. Provide manual testing instructions

🦊 Browser testing

Desktop

  • Edge (latest)
  • Chrome
  • Firefox
  • Safari

📸 Screenshots

Description Screenshot
Desktop
usage.gif

* Introduces `Connection` class to handle WebSocket connections.
* Defines connection states (connecting, connected, closing, closed) and
exposes getters.
* Implements event listeners for connection state changes and messages.
* Creates `TransactionManager` class to manage transactions over the
connection.
* Enables queuing transactions when the connection is unavailable.
* Binds `TransactionManager` to the `Connection` for message handling.

This commit is part of a major change to support reliable communication
and transaction management.
* Introduces `isSipError`, `isSipHangupEvent`, `isSIPIncomingCallMessage`,
`isSIPCallAcceptedEvent`, and `isSipRingingEvent` functions in `janus.ts` to
identify specific Janus response types for SIP events.
* Adds a `deferredPromise` function in `promise.ts` to create deferred
promises for asynchronous operations.

These functions enhance code readability and provide flexible promise
control for improved message and task management.
* Includes eventemitter3 for event management within the connection class.

This dependency provides a robust event system for the WebSocket connection.
* Introduces `KeepAliveAgent` class to maintain connection health.
* Utilizes `Connection` and `transactionManager` for communication.
* Sends periodic keep-alive transactions (default 10 seconds) to the server.
* Monitors connection state and restarts keep-alive on reconnection.
*  Implements failure handling with a configurable retry mechanism.

This feature ensures the connection remains active and facilitates reliable
communication.
* Introduces `SIPRegistrationAgent` class to handle SIP registration.
* Interacts with `Connection`, `transactionManager`, and `Handler` for
communication.
* Manages registration state (`unregistered`, `registering`, `registered`,
`error`).
* Sends SIP registration transactions using `transactionManager`.
* Handles registration responses, updating state and triggering events.
* Implements error handling and signaling through events.
* Includes a placeholder for `unregister()` for future implementation.

This feature enables automatic SIP registration with error handling and
event notifications.
* Introduces `Call` class to represent SIP calls.
* Manages call states (new, connecting, ringing, active, held, done).
* Handles incoming and outbound call scenarios.
* Provides methods for answering, hanging up, and getting call stats
(placeholder).
* Includes functionality for setting Telnyx call control IDs.

feat: implement call-agent for handling sip call interactions

* Introduces `CallAgent` class for managing SIP call flow.
* Creates and manages `Call` instances for incoming and outgoing calls.
* Interacts with `Connection`, `Peer`, `TransactionManager`, and `Handler`.
* Handles incoming call events (`SIPIncomingCallMessage`).
* Handles SIP hangup events (`JanusSIPHangupEvent`).
* Handles SIP call accepted events (`JanusSIPCallAcceptedEvent`).
* Triggers events (`SwEvent.Notification`) for call updates.
* Implements audio handling for ringtones and ringback tones.

feat: Implement Peer class for WebRTC peer connections

* Introduces `Peer` class to handle WebRTC peer connections for calls.
* Supports creating offer and answer peers based on call options.
* Handles local media stream acquisition with constraints.
* Manages adding media tracks to the peer connection.
* Provides methods for handling ICE trickles and negotiation needed events.
* Implements methods for setting remote SDP and closing the connection.
* Triggers events (`SwEvent.MediaError`) for media acquisition failures.

feat: Implement ICETrickleTransaction for sending ICE candidates

* Introduces `ICETrickleTransaction` to send ICE candidates to Janus.
* Constructs a Janus `trickle` request with candidate information.
* Handles success and error responses from Janus on message received.

feat: Implement SIPAnswerTransaction for sending SIP answer

* Introduces `SIPAnswerTransaction` for sending SIP answer messages.
* Constructs a Janus `message` request with answer SDP and other details.
* Handles success (`isSIPCallAcceptedEvent`) and error (`isSipError`)
responses.
* Resolves with call ID on successful SIP answer reception.

feat: Implement SIPCallTransaction for initiating SIP calls

* Introduces `SIPCallTransaction` for initiating SIP calls via Janus.
* Constructs a Janus `message` request with call details, URI, and SDP.
* Handles success (`isSipRingingEvent`) and error (`isSipError`) responses.
* Resolves with call ID, Telnyx IDs, on successful SIP call initiation.

feat: Implement SIPHangupTransaction for terminating SIP calls

* Introduces `SIPHangupTransaction` for sending SIP hangup messages.
* Constructs a Janus `message` request with the hangup request.
* Handles success (`janus === ack`) and error (`janus === error`) responses.
* Resolves with `true` on successful SIP hangup.
* Introduces JanusClient class as the central component for SIP calls.
* Manages connection to Janus server, plugin attachment, and SIP
registration.
* Handles call creation and management through CallAgent.
* Provides methods for connecting, making calls, getting calls, and setting
remote media element.
* Includes event handling for listening to call events.
* Implements stubs for enabling/disabling webcam and disconnection (to be
completed).

BREAKING CHANGE: Introduces a new class for core functionality, potentially
affecting code organization and usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant