undefined

Cordova Chat code sample - How To guide

Here we explain how to run origin TextChat JavaScript code sample for browser on Cordova/PhoneGap environment

Attention! Complete Chat API integration guide for Web/Javascript and Hybrid apps is here

Integration details

  1. Make sure you have the latest Cordova installed:

    cordova --version

    The output will be something like this:

    8.0.0

    If Cordova is not installed - run the following command:

    npm install -g cordova
  2. Create Cordova app:

    cordova create sample-chat-cordova com.sample.chat SampleChatCordova

    You can use the Create your first Cordova app guide to get more info how to create your 1st Cordova app.

  3. Change directory to newly created Cordova app:

    cd sample-chat-cordova
  4. Add platforms:

    cordova platform add ios --save
    cordova platform add android --save
    cordova platform add browser --save
  5. Install WebSocket-for-Android plugin to support WebSockets on Android < 4.4. We need WebSockets to work for Chat functionality:

    cordova plugin add cordova-plugin-websocket
  6. Install cordova-plugin-device plugin:

    cordova plugin add cordova-plugin-device
  7. Install cordova-custom-config plugin

    cordova plugin add cordova-custom-config

    Then add the following lines into config.xml (for iOS 10+, to support files attachments in sample):

    <platform name="ios">
     ...
     <config-file platform="ios" target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
       <string>Access to photo library for file attachments</string>
     </config-file>
     <config-file platform="ios" target="*-Info.plist" parent="NSCameraUsageDescription">
       <string>Access to camera for file attachments</string>
     </config-file>
    </platform>
  8. Install iOS Deployment Tools if you want to launch iOS app on iOS device.

  9. Copy content from sample-chat-browser folder to www folder of your Cordova app. The following command can be used for it:

    cp -r sample-chat-browser/* sample-chat-cordova/www/
  10. Connect cordova.js at your index.html file:

    <script type="text/javascript" src="cordova.js"></script>
  11. Finally, use the following commands to run the sample:

    cordova clean browser && cordova run browser
    cordova clean ios && cordova run ios --device # for run on device
    cordova clean ios && cordova emulate ios # for run on emulator
    cordova clean android && cordova run android --device # for run on device
    cordova clean android && cordova emulate android # for run on emulator

Debugging

The following tools will help you debug your Cordova application:

Can't build yourself?

Got troubles with building Cordova code sample? Just create an issue at Issues page - we will create the sample for you. For FREE!