-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement janus-client class for core sip client functionality
* 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.
- Loading branch information
Showing
3 changed files
with
112 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { Call } from './Call'; | ||
import { Connection } from './Connection'; | ||
import { deRegister, register } from './Handler'; | ||
import KeepAliveAgent from './KeepAliveAgent'; | ||
import { SIPRegistrationAgent } from './SIPRegistrationAgent'; | ||
import { transactionManager } from './TransactionManager'; | ||
import { Environment } from './constants'; | ||
import { IClientOptions } from './interfaces'; | ||
import { AttachSipPluginTransaction } from './transactions/AttachSIPPlugin'; | ||
import { CreateSessionTransaction } from './transactions/CreateSession'; | ||
import CallAgent from './CallAgent'; | ||
import { ICallOptions } from 'src/utils/interfaces'; | ||
|
||
export default class JanusClient { | ||
private _gatewaySessionId: number | null = null; | ||
private _gatewayHandleId: number | null = null; | ||
private _connection: Connection; | ||
private _options: IClientOptions; | ||
private _sipRegistrationAgent: SIPRegistrationAgent; | ||
private _keepAliveAgent: KeepAliveAgent; | ||
private _callAgent: CallAgent; | ||
|
||
static telnyxStateCall(call: Call) { | ||
return call; | ||
} | ||
constructor(options: IClientOptions) { | ||
this._connection = new Connection({ | ||
environment: Environment.production, | ||
}); | ||
this._options = options; | ||
} | ||
|
||
public async connect() { | ||
this._connection.connect(); | ||
|
||
const { sessionId } = await transactionManager.execute( | ||
new CreateSessionTransaction() | ||
); | ||
|
||
this._gatewaySessionId = sessionId; | ||
|
||
const { handleId } = await transactionManager.execute( | ||
new AttachSipPluginTransaction({ | ||
sessionId: this._gatewaySessionId, | ||
}) | ||
); | ||
this._gatewayHandleId = handleId; | ||
|
||
this._keepAliveAgent = new KeepAliveAgent({ | ||
connection: this._connection, | ||
gatewaySessionId: this._gatewaySessionId, | ||
}); | ||
|
||
this._sipRegistrationAgent = new SIPRegistrationAgent({ | ||
connection: this._connection, | ||
options: this._options, | ||
sessionId: this._gatewaySessionId, | ||
handleId: this._gatewayHandleId, | ||
}); | ||
|
||
this._callAgent = new CallAgent({ | ||
gatewayHandleId: this._gatewayHandleId, | ||
gatewaySessionId: this._gatewaySessionId, | ||
connection: this._connection, | ||
}); | ||
|
||
await this._sipRegistrationAgent.register(); | ||
this._keepAliveAgent.start(); | ||
} | ||
|
||
async newCall(options: ICallOptions) { | ||
const call = await this._callAgent.Outbound({ | ||
...options, | ||
handleId: this._gatewayHandleId, | ||
sessionId: this._gatewaySessionId, | ||
}); | ||
return call; | ||
} | ||
|
||
get calls() { | ||
return this._callAgent.calls; | ||
} | ||
public disconnect() { | ||
// TODO - implement | ||
} | ||
|
||
public enableWebcam() { | ||
// TODO - implement | ||
return true; | ||
} | ||
public disableWebcam() { | ||
// TODO - implement | ||
return true; | ||
} | ||
|
||
set remoteElement( | ||
element: HTMLMediaElement | string | (() => HTMLMediaElement) | ||
) { | ||
this._callAgent.remoteElement = element; | ||
} | ||
|
||
on(eventName: string, callback: Function) { | ||
register(eventName, callback); | ||
} | ||
off(eventName: string, callback: Function) { | ||
deRegister(eventName, callback); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Client' |
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