项目作者: m1ga

项目描述 :
Vonage module for Appcelerator Titanium
高级语言: Java
项目地址: git://github.com/m1ga/ti.vonage.git
创建时间: 2020-05-01T10:17:26Z
项目社区:https://github.com/m1ga/ti.vonage

开源协议:Other

下载


Vonage module for Titanium SDK




Buy Me A Coke donate button

Requirements

  • Titanium SDK 12+ (Android), 9.2.0+ (iOS)
  • Vonage (formerly OpenTok) account
  • For Android: Add the following like to your [app]/platform/android/build.gradle

    1. repositories {
    2. mavenCentral()
    3. }

    and <uses-sdk android:minSdkVersion="24"></uses-sdk> in you tiapp.xml.

  • For iOS: Add the following privacy keys to the section of your tiapp.xml:

    1. <key>NSCameraUsageDescription</key>
    2. <string>We need to access your camera (use your own description)</string>
    3. <key>NSMicrophoneUsageDescription</key>
    4. <string>We need to access your microphone (use your own description)</string>

API

Properties

  • apiKey
  • sessionId
  • token
  • audioOnly (creation only)

Methods

  • connect
  • disconnect

Events

  • ready
  • disconnected
  • streamReceived: view, userType, streamId, connectionData, connectionId, connectionCreationTime
  • streamDropped
  • sessionError
  • streamCreated
  • streamDestroyed
  • error

How to use it

Listen to the streamReceived event. It will return a view with the videos. You’ll add those views to your normal Ti app. The userType and streamId will help you to e.g. remove them later again if a participant will disconnect.

Example

  1. <modules>
  2. <module>ti.vonage</module>
  3. </modules>
  1. import TiVonage from 'ti.vonage';
  2. const API_KEY = ''; // Get from https://tokbox.com/developer/
  3. const SESSION_ID = ''; // Get from https://tokbox.com/developer/tools/playground/
  4. const TOKEN = ''; // Get from https://tokbox.com/developer/tools/playground/
  5. const AUDIO_ONLY = false;
  6. function onOpen() {
  7. // iOS requires some privacy permissions first
  8. Ti.Media.requestCameraPermissions(event => {
  9. if (!event.success) {
  10. alert('No access to camera!');
  11. }
  12. Ti.Media.requestAudioRecorderPermissions(event => {
  13. if (!event.success) {
  14. alert('No access to microphone!');
  15. }
  16. TiVonage.initialize();
  17. });
  18. });
  19. }
  20. TiVonage.addEventListener('ready', () => {
  21. console.log('ready');
  22. });
  23. TiVonage.addEventListener('streamReceived', event => {
  24. // view with the camera stream:
  25. const view = Ti.UI.createView({
  26. height: 190,
  27. width: 190
  28. });
  29. view.add(event.view);
  30. window.add(view);
  31. console.log('Type:', event.userType);
  32. if (event.userType == 'subscriber') {
  33. console.log('Stream id:', event.streamId);
  34. console.log('Connection data:', event.connectionData);
  35. console.log('Connection id:', event.connectionId);
  36. console.log('Connection time:', event.connectionCreationTime);
  37. }
  38. });
  39. TiVonage.addEventListener('streamDropped', event => {
  40. console.log(event.userType, event.streamId);
  41. });
  42. function onClickConnect() {
  43. TiVonage.apiKey = API_KEY;
  44. TiVonage.sessionId = SESSION_ID;
  45. TiVonage.token = TOKEN;
  46. TiVonage.audioOnly = AUDIO_ONLY;
  47. TiVonage.connect();
  48. }
  49. function onClickDisconnect() {
  50. TiVonage.disconnect();
  51. }
  52. const window = Ti.UI.createWindow();
  53. const btn = Ti.UI.createButton({ title: 'Connect' });
  54. window.addEventListener('open', onOpen);
  55. btn.addEventListener('click', onClickConnect);
  56. window.add(btn);
  57. window.open();

License

Apache 2.0

Author