Skip to content

Commit

Permalink
misc: upgrade agent sdk (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
embbnux authored Jul 29, 2024
1 parent 668cf19 commit 5fa3894
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 21,549 deletions.
7 changes: 6 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const evAgentConfig = {
isSecureSocket: true,
allowMultiSocket: true,
authHost: process.env.ENGAGE_VOICE_AUTH_SERVER,
clientAppType: "RCX_Embeddable",
clientAppVersion: "0.2.0",
componentName: "EAG",
isI18nEnabled: false,
};

const authConfig = {
Expand Down Expand Up @@ -131,7 +135,8 @@ export async function devServer() {
publicPath: '/',
},
port,
hot: true,
hot: false,
webSocketServer: false,
}, compiler);
await server.start();
console.log(`Brand: ${brand}: server listening to ${port}...`);
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
"react-router-redux": "^4.0.7",
"redux": "^4.0.4",
"ringcentral-client": "^1.0.0-beta.2",
"sip.js": "0.13.5",
"styled-components": "^5.3.3"
},
"resolutions": {
"sip.js": "0.13.5"
}
}
4 changes: 3 additions & 1 deletion src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';

import './lib/patch';
import './lib/BroadcastChannel.polyfill';

import { createPhone } from './modules/Phone';
Expand Down Expand Up @@ -40,7 +40,9 @@ if (rcServer) {
}
if (evServer) {
evSdkConfig.authHost = evServer;
window.evAuthHost = evServer;
}

// @ts-ignore
const phone = createPhone({
sdkConfig,
Expand Down
12 changes: 11 additions & 1 deletion src/lib/getWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getWebpackConfig({
const base = getBaseWebpackConfig({
mode: environment,
themeFolder: brandFolder,
babelLoaderExcludes: /node_modules|engage-voice-agent/
babelLoaderExcludes: /node_modules|vendor/
});
const scssLoader = base.module.rules.find((rule) => rule.test.test('x.scss'));
// TODO: fix scss syntax error in widgets
Expand All @@ -34,6 +34,16 @@ function getWebpackConfig({
replace: 'and (max-width',
},
});
base.module.rules.push({
test: /agentLibrary\.js$/,
use: {
loader: 'string-replace-loader',
options: {
search: 'window.location.origin',
replace: 'window.evAuthHost',
},
}
});
return {
...base,
entry: {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/patch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-ignore
window.evAuthHost = process.env.AGENT_CONFIG.authHost; // For hack EV SDK
50 changes: 49 additions & 1 deletion src/modules/EvClient/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { EvClient as EvClientBase } from '@ringcentral-integration/engage-voice-widgets/lib/EvClient';
import { EvCallbackTypes } from '@ringcentral-integration/engage-voice-widgets/lib/EvClient/enums/callbackTypes';
import { EvCallbackTypes, evStatus } from '@ringcentral-integration/engage-voice-widgets/lib/EvClient/enums';
import { Module } from '@ringcentral-integration/commons/lib/di';

import type {
EvACKResponse,
EvAuthenticateAgentWithRcAccessTokenRes,
EvTokenType,
RawEvAuthenticateAgentWithRcAccessTokenRes,
} from '@ringcentral-integration/engage-voice-widgets/lib/EvClient/interfaces';

const AGENT_TYPES = {
AGENT: 'agent',
SUPERVISOR: 'supervisor',
};

@Module({
name: 'EvClient',
deps: [
{ dep: 'Environment' },
{ dep: 'Locale' },
{ dep: 'EvClientOptions', optional: true }
],
})
Expand Down Expand Up @@ -51,4 +64,39 @@ export class EvClient extends EvClientBase {
dialDest,
});
}

authenticateAgent(rcAccessToken: string, tokenType: EvTokenType) {
return new Promise<EvAuthenticateAgentWithRcAccessTokenRes>((resolve) => {
this.setAppStatus(evStatus.LOGIN);
this._sdk.authenticateAgentWithRcAccessToken(
rcAccessToken,
tokenType,
async (res: RawEvAuthenticateAgentWithRcAccessTokenRes) => {
// For Session in Agent SDK
localStorage.setItem('engage-auth:tokenType', res.tokenType);
localStorage.setItem('engage-auth:accessToken', res.accessToken);
localStorage.setItem('engage-auth:refreshToken', res.refreshToken);
// here just auth with engage access token, not need handle response data, that handle by Agent SDK.
await this.authenticateAgentWithEngageAccessToken(res.accessToken);

let locale = res.regionalSettings?.language;
if (locale) {
this._deps.locale.setLocale(locale);
this._eventEmitter.emit('setLocale', locale);
}
this.setAppStatus(evStatus.LOGINED);
const _agents = (res || {}).agents || [];
const agents = _agents.map((agent) => ({
...agent,
agentId: agent && agent.agentId ? `${agent.agentId}` : '',
agentType: AGENT_TYPES[agent.agentType],
}));
resolve({
...res,
agents,
});
},
);
});
}
}
8 changes: 1 addition & 7 deletions vendor/agentLibrary.js

Large diffs are not rendered by default.

Loading

0 comments on commit 5fa3894

Please sign in to comment.