See Hipmob in action on iOS with Wanderplayer and Android with Wanderplayer
Sign Up Here
Peer to Peer Chat with Hipmob
Overview
Hipmob provides hosted live chat for mobile apps. You sign up with us, we give you a code, you download our library, you integrate it into your app, and you can then talk to your users, figure out what they want and what problems they are having, and make them happy. No servers, no extra steps or code to write, wherever the users are, you get to focus on what you do well. This document covers integrating the Hipmob peer-to-peer experience into your iPhone or iPad app(s).
Background
Hipmob supports both support chat (covered in the standard Android and iOS documentation) and peer-to-peer chat (covered here). The only difference between peer-to-peer chat and support chat is that for peer-to-peer chat a peer has to be specified. For support chat no peer is necessary: our communication network routes the messages to any available operators.
Specifying the peer is straightforward: you use your app's existing user identifiers as Hipmob device identifiers.
Note Because Hipmob does not parse the provided device identifier or look at it in any other way, the Hipmob communication network will accept the same device identifier for multiple devices. Note that future functionality may depend on uniqueness of the device identifier.
Quick Start - Android
To integrate Hipmob into your own project, read on.
- Register for an account at https://manage.hipmob.com/ (if you haven't already done so). Once you register a Hipmob application entry will be created for you and an application ID will be generated. Remember this application ID: you'll use it later.
- Download the Hipmob Android library JAR file. This includes all the dependencies required (see the Library Options section for more details).
- Copy the Hipmob library JAR file into your project's library folder (libs, if you're using the default project folder structure in Eclipse).
- Add the Hipmob library JAR file into your project's build path.
- Add the INTERNET, WRITE_EXTERNAL_STORAGE and RECORD_AUDIO permissions to the AndroidManifest.xml file.
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />
- Add the HipmobCore activity definition to the AndroidManifest.xml file.
<activity android:name="com.hipmob.android.HipmobCore" />
- Use an Intent to call the HipmobCore activity. You'll need the application ID from step 1: pass that as HIPMOB_KEY. You will also need to set the host application device id, and then specify the peer to chat with.
// create an intent Intent i = new Intent(this, com.hipmob.android.HipmobCore.class); // REQUIRED: set the appid to the key you're provided i.putExtra(HipmobCore.KEY_APPID, HIPMOB_KEY); // REQUIRED: pass the host application identifier. i.putExtra(HipmobCore.KEY_USERID, "my-user-identifier-that-is-unique"); // REQUIRED: pass the peer's host application identifier. i.putExtra(HipmobCore.KEY_PEER, "their-user-identifier-that-is-unique"); // launch the chat window startActivity(i);
Connect it to a button (you can see an example in the WanderPlayer app in the Google Play Store). - And we're complete. Build your app.
Quick Start - iOS
To integrate Hipmob into your own iOS project, read on.
- Register for an account at here (if you haven't already done so). Once you register a Hipmob application entry will be created for you and an application ID will be generated. Remember this application ID: you'll use it later.
- Download the Embedded Hipmob iOS Framework . This includes all the built dependencies required (see the Framework Options section for more details).
- Copy the Hipmob framework folder into your project. You may also add it by going into your build phases and selecting Link Binary With Libraries, but it is a little trickier. For this, you will need to add the framework folder that is inside the embedded framework. After you add this, you will also need to add the resources from inside the embedded framework into the Copy Bundle Resources also under Bundle Phases.
- Add the following Framework Dependencies
- libicucore.dylib
- CFNetwork.framework
- Security.framework
- Foundation.framework
-
Include the hipmob header wherever you will be creating hipmob viewcontroller.
#include <hipmob/hipmob.h>
-
Initialize the hipmob VC with your
HIPMOB_KEY
from above.
hipmob *supportvc = [[[hipmob alloc] initWithAppID:HIPMOB_KEY] autorelease];
You can instead initialize with a custom title as well.hipmob *supportvc = [[[hipmob alloc] initWithAppID:HIPMOB_KEY andTitle:SUPPORTTITLE] autorelease];
-
Specify the current users deviceid as well as the peer you want to connect to. When specifying a peer you need to make sure that they have been added as friends through our API. You can see more information about this in the Managing Friends.
supportvc.localdeviceid=YOUR_DEVICE_ID supportvc.peerdeviceid=YOUR_FRIEND_DEVICE_ID
-
Present the hipmob viewcontroller modally.
[self presentModalViewController:supportvc animated:YES];
- And we're complete. Build your app.
Details
Managing Friends
To prevent sending and receiving of spam messages Hipmob requires the use of friend lists that keep track of which devices are permitted to send/receive messages from one another. The friend list can be managed using the Hipmob Server API.
Android Configuration Options
All configurations options documented in the Android guide can be used: peer-to-peer functionality provides an additional configuration option to specify the chat recipient.
Peer
Description
The application must provide the peer's device identifier. This is passed back to the Hipmob communication network and is used to route messages to the appropriate device. The device identifier is treated as an opaque key by the Hipmob communication network: it is not parsed or processed in any way, just stored. If present, it is written out into the transcripts.
Required
Yes
Since:
Version 1.0 (Beta 2)
Extra Name:
com.android.hipmob.HipmobCore.KEY_PEER
Usage
// create an intent
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);
// REQUIRED: set the appid to the key you're provided
i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f");
// set the device identifier
i.putextra(HipmobCore.KEY_DEVICEID, "my-magical-device-identifier");
// REQUIRED: pass the peer's host application identifier.
i.putExtra(HipmobCore.KEY_PEER, "their-device-identifier-that-is-unique");
// launch the chat window
startActivity(i);
Note Because Hipmob does not parse the provided device identifier or look at it in any other way, the Hipmob communication network will accept the same device identifier for multiple devices. Note that future functionality may depend on uniqueness of the device identifier.
PeerDeviceID
Description
This application must provide the peer's device identifier. This is passed back to the Hipmob communication network and is used to route messages to the appropriate device. The device identifier is treated as an opaque key by the Hipmob communication network: it is not parsed or processed in any way, just stored. If present, it is written out into the transcripts.
Required:
YES
Since:
Version 1.3
Type:
NSString
Usage:
Set this variable as part of the hipmob object BEFORE you have the hipmob object appear so that it will be sent to the servers and you will initiate a p2p conversation.
supportvc.peerdeviceid=YOUR_FRIEND_DEVICE_IDNote Because Hipmob does not parse the provided device identifier or look at it in any other way, the Hipmob communication network will accept the same device identifier for multiple devices. Note that future functionality may depend on uniqueness of the device identifier.
receivedMessageFromID
Description
Delegate callback that lets you see whenever messages are received from peers that are not the one you are connected to. If a support message is sent this way it is sent with the id "SUPPORT." The return value of this function decides whether a statement is printed on the users message feed that a message was sent to them or not.
Required:
No
Since:
Version 1.3
Type:
Method
Name:
receivedMessageFromID:
Parameters:
(NSString*)senderid
Usage:
Implement this in any object you declare as a hipmobVCDelegate
-(BOOL)receivedMessageFromID:(NSString *)senderid{
NSLog(@"User with id %@ sent you a message", senderid);
return TRUE;
}
