nativescript-glia
添加插件描述
npm i --save nativescript-glia

nativescript-glia

ns plugin add nativescript-glia

使用说明

iOS 权限

您必须在应用的 Info.plist 文件中添加以下权限,通常位于应用的 App_Resources/iOS 目录下。将 string 改为您喜欢的特定权限。

	<key>NSPhotoLibraryAddUsageDescription</key>
<string>Need photo library access for adding images</string>

<key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for uploading videos</string>

<key>NSCameraUsageDescription</key>
<string>Need camera access for uploading images</string>

Android 权限

插件会自动添加,您无需自行配置。

	<!-- Permission to draw on top of other apps, used for annotations during screen
sharing. Visitor must also explicitly grant this permission to the app through a
permission management screen during the screen sharing session.
-->

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

Android 应用配置

您需要扩展 android 的 Application 以使用 Glia。您可以在 NativeScript 文档 中找到有关信息。

在应用项目的根目录下创建一个名为 application.android.ts 的文件。复制以下内容。

  • 您需要将 JavaProxy 文件名以及 Glia 站点 Id、ApiKey、ApiSecret 值更改为您的 Glia 密钥。您需要将 JavaProxy 文件名复制到应用的 AndroidManifest.xml 文件中,位于 AppResources/Android 目录下,并用您的文件名替换 <application android:name="YOUR_JAVA_PROXY_NAME">。在这个例子中将是:
	<application
android:name="org.myApp.GliaDemoApp"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
// the `JavaProxy` decorator specifies the package and the name for the native *.JAVA file generated.
@NativeClass()
@JavaProxy('org.myApp.GliaDemoApp')
class Application extends android.app.Application {
public onCreate(): void {
super.onCreate();

// At this point modules have already been initialized

// Enter custom initialization code here

com.glia.widgets.GliaWidgets.onAppCreate(this);

com.glia.widgets.GliaWidgets.init(
new com.glia.widgets.GliaWidgetsConfig.Builder()
.setSiteApiKey(new com.glia.androidsdk.SiteApiKey('SITE_APIKEY_ID', 'SITE_APIKEY_SECRET'))
.setSiteId('SITE_ID')
.setRegion('us')
.setContext(this.getApplicationContext())
.build()
);
}

public attachBaseContext(baseContext: android.content.Context) {
super.attachBaseContext(baseContext);
// This code enables MultiDex support for the application (if needed)
// androidx.multidex.MultiDex.install(this);
}
}

最后,当使用 NativeScript 扩展 Android Application 时,我们需要确保文件在 Webpack 打包时正确处理。在 NativeScript 7+ 中,您需要使用 chainWebpack 方法,如下所示:

const webpack = require('@nativescript/webpack');

module.exports = (env) => {
webpack.init(env);

webpack.chainWebpack((config) => {
if (webpack.Utils.platform.getPlatformName() === 'android') {
// make sure the path to the applicatioon.android.(js|ts)
// is relative to the webpack.config.js
// you may need to use `./app/application.android if
// your app source is located inside the ./app folder.
config.entry('application').add('./application.android');
}
});

return webpack.resolveConfig();
};

在 NativeScript 7 之前的版本中,文档可以在此处找到 https://v6.docs.nativescript.org/angular/core-concepts/android-runtime/advanced-topics/extend-application-activity。基本上,您需要在您的 webpack.config.js 文件中做以下操作:

 entry: {
bundle: entryPath,
application: "./application.android",
},

API

  • Glia.configure(config: GliaConfiguration) - 配置 Glia 实例。_ 必须在其他方法之前调用 _
  • Glia.listQueues() : 返回队列数组。
  • Glia.start(config: StartConfiguration) - 为给定选项启动参与。

示例

import { EngagementKind, Environment, Glia, IGliaQueue, StartConfiguration } from 'nativescript-glia';

export SomeClass {
constructor() {

}

// Configure the Glia instance before calling any other methods
public configureGlia() {
Glia.configure({
siteId: "YOUR_SITE_ID",
region: 'us',
authorizingMethod: {
siteApiKey: {
id: "YOUR_SITE_APIKEY_ID",
secret: "YOUR_SITE_APIKEY_SECRET",
},
},
}).then(() => {
console.log('*** Glia Configured ***');
}).catch((err) => {
console.log('Glia Configure Error', err);
});
}

public getMyQueues() {
try {
const queues = await Glia.listQueues();
// iterate your queues here if you need to find a specific queue capable of video/audio/chat or something else.
// queues can be inspected with the following approach
const name = (queues[0] as IGliaQueue).name;
const status = (queues[0] as IGliaQueue).state.status;
const media = (queues[0] as IGliaQueue).state.media;
} catch (error) {
console.log(error);
}
}

public startChatGlia() {
try {
const startOpts: StartConfiguration = {
companyName: 'YOUR COMPANY NAME',
engagementKind: EngagementKind.Chat,
configuration: {
authorizationMethod: {
siteApiKey: { id: 'YOUR_SITE_APIKEY_ID', secret: 'YOUR_SITE_APIKEY_SECRET' },
},
environment: Environment.USA,
siteId: 'YOUR_SITE_ID',
},
queueID: 'YOUR_QUEUE_ID',
visitorContext: {
type: 'page',
url: 'YOUR_SITE_URL',
},
};
await Glia.start(startOpts);
} catch (error) {
console.log(error);
}
}
}

许可证

Apache License 版本 2.0