Skip to content

Commit

Permalink
feat(WEBRTC-52): migrate module verto to telnyx_rtc (#10)
Browse files Browse the repository at this point in the history
* change default verto values to be telnyx_rtc values

* create folder modules

* add rtcdev url

* update unit tests and change port 14939 to be 14938, we don't support more 14939

* remove comments console.log

* upgrade version in examples/react
  • Loading branch information
DeividVeloso authored Feb 12, 2020
1 parent 145f76c commit ba11a18
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 219 deletions.
2 changes: 1 addition & 1 deletion examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@telnyx/webrtc": "1.0.4"
"@telnyx/webrtc": "1.0.6"
},
"devDependencies": {
"@babel/core": "^7.6.2",
Expand Down
41 changes: 11 additions & 30 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
70 changes: 27 additions & 43 deletions src/TelnyxRTC/Verto.ts → src/Modules/TelnyxRTC/Verto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import VertoConf from './ConfMan';
import VertoDialog from './Dialog';
import VertoRTC from './RTC';
import Enum from './Enum';
import { Module } from '../utils/types';
import { Module } from '../../utils/types';

interface DeviceParams {
useCamera?: 'none' | 'any' | string;
Expand All @@ -54,8 +54,8 @@ interface VideoParams {
}

// These are currently unused by Telnyx.
interface LoginParams {}
interface UserVariables {}
interface LoginParams { }
interface UserVariables { }
interface IceServer {
urls: string | [string];
username?: string;
Expand Down Expand Up @@ -140,8 +140,6 @@ export default class Verto {
}

connect(params = this.params, callbacks = this.callbacks) {
// console.log('verto connect', this.options.socketUrl);

if (!params || !params.socketUrl) {
return;
}
Expand All @@ -163,7 +161,6 @@ export default class Verto {
iceServers: false,
ringSleep: 6000,
sessid: null,
// la: new VertoLiveArray(),
onmessage: (e) => {
return this.handleMessage(e.eventData);
},
Expand Down Expand Up @@ -238,10 +235,10 @@ export default class Verto {
}
console.error(
'Websocket Lost ' +
this.ws_cnt +
' sleep: ' +
this.ws_sleep +
'msec'
this.ws_cnt +
' sleep: ' +
this.ws_sleep +
'msec'
);
this.to = setTimeout(() => {
console.log('Attempting Reconnection....');
Expand Down Expand Up @@ -284,7 +281,7 @@ export default class Verto {
}

purge() {
// console.log('purging dialogs');
// purging dialogs
Object.keys(this.dialogs).forEach((dialog) => {
this.dialogs[dialog].setState(Enum.state.purge);
});
Expand Down Expand Up @@ -327,7 +324,6 @@ export default class Verto {
this.q.push(requestJson);
} else {
// We have a socket and it should be ready to send on.
// console.log(requestJson);
this._ws_socket.send(requestJson);
}
// Setup callbacks. If there is an id, this is a call and not a notify.
Expand Down Expand Up @@ -420,27 +416,23 @@ export default class Verto {
},
this._ws_callbacks[response.id].request_obj.method == 'login'
? (e) => {
this.authing = false;
// console.log('logged in');
delete this._ws_callbacks[response.id];
if (this.options.onWSLogin) {
this.options.onWSLogin(this, true);
}
this.authing = false;
// console.log('logged in');
delete this._ws_callbacks[response.id];
if (this.options.onWSLogin) {
this.options.onWSLogin(this, true);
}
}
: (e) => {
this.authing = false;
// console.log(
// 'logged in, resending request id: ' + response.id
// );
if (this._ws_socket) {
this._ws_socket.send(orig_req);
}
if (this.options.onWSLogin) {
this.options.onWSLogin(this, true);
}
},
this.authing = false;
if (this._ws_socket) {
this._ws_socket.send(orig_req);
}
if (this.options.onWSLogin) {
this.options.onWSLogin(this, true);
}
},
(e) => {
// console.log('error logging in, request id:', response.id);
delete this._ws_callbacks[response.id];
error_cb(response.error, this);
if (this.options.onWSLogin) {
Expand Down Expand Up @@ -605,8 +597,6 @@ export default class Verto {
data.params.msg
);
}
//console.error(data);
// console.debug("MESSAGE from: " + data.params.msg.from, data.params.msg.body);
break;
case `${this.module}.clientReady`:
if (this.callbacks.onMessage) {
Expand Down Expand Up @@ -641,16 +631,14 @@ export default class Verto {
Object.keys(e.subscribedChannels || {}).forEach((channel) => {
this.eventSUBS[channel].forEach((sub) => {
sub.ready = true;

// console.log('subscribed to channel: ' + channel);
if (sub.readyHandler) {
sub.readyHandler(this, channel);
}
});
});
break;
case `${this.module}.unsubscribe`:
//console.error(e);
console.error(e);
break;
}
}
Expand All @@ -662,7 +650,6 @@ export default class Verto {
(e) => {
/* Success */
this.processReply(method, true, e);
// console.log('sendMethod success', e);
if (success_cb) success_cb(e);
},
(e) => {
Expand Down Expand Up @@ -829,7 +816,7 @@ export default class Verto {
}

sendChannels = Object.keys(unsubChannels).map((i) => {
// console.log('Sending Unsubscribe for: ', i);
// Sending Unsubscribe
return i;
});

Expand All @@ -856,7 +843,7 @@ export default class Verto {
}

logout(msg?) {
// console.log('verto logout', msg);
// verto logout
this.closeSocket();
if (this.callbacks.onWSClose) {
this.callbacks.onWSClose(this, false);
Expand Down Expand Up @@ -925,7 +912,6 @@ export default class Verto {
}

login(msg?) {
// this.logout();
this.call('login', {});
}

Expand All @@ -948,7 +934,7 @@ Verto.audioInDevices = [];
Verto.audioOutDevices = [];
Verto.unloadJobs = [];
Verto.checkDevices = (runtime?: any) => {
// console.info('enumerating devices');

const aud_in = [];
const aud_out = [];
const vid = [];
Expand All @@ -957,7 +943,7 @@ Verto.checkDevices = (runtime?: any) => {
// Handles being called several times to update labels. Preserve values.
deviceInfos.forEach((deviceInfo) => {
let text = '';
// console.log(deviceInfo);

if (deviceInfo.kind === 'audioinput') {
text = deviceInfo.label || 'microphone ' + (aud_in.length + 1);
aud_in.push({
Expand All @@ -979,8 +965,6 @@ Verto.checkDevices = (runtime?: any) => {
kind: 'video',
label: text,
});
} else {
// console.log('Some other kind of source/device: ', deviceInfo);
}
});

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/TelnyxRTCClient/ITelnyxRTCDialog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TelnyxRTCCallState } from '../TelnyxRTC/Enum';
import { TelnyxRTCCallState } from '../Modules/TelnyxRTC/Enum';

/**
* @hidden
Expand Down
4 changes: 2 additions & 2 deletions src/TelnyxRTCClient/TelnyxRTCCall.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CallState } from '../utils/types';
import { ICall } from '../utils/interfaces';
import ITelnyxRTCDialog from './ITelnyxRTCDialog';
import { TelnyxRTCCallState } from '../TelnyxRTC/Enum';
import { TelnyxRTCCallState } from '../Modules/TelnyxRTC/Enum';

/**
* @hidden
*/
export default class TelnyxRTCCall implements ICall {
constructor(private call: ITelnyxRTCDialog) {}
constructor(private call: ITelnyxRTCDialog) { }

get state(): CallState {
switch (this.call.state) {
Expand Down
Loading

0 comments on commit ba11a18

Please sign in to comment.