Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

OpenTok Text Chat Accelerator Pack enables text messages between mobile or browser-based devices.

License

Notifications You must be signed in to change notification settings

opentok/accelerator-textchat-ios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text Chat Accelerator Pack iOS

Build Status Version Status license MIT Platform PRs Welcome codebeat badge

Tokbox is now known as Vonage

This project is deprecated

The OpenTok Text Chat Accelerator Pack for iOS project is now a part of Accelerator Core iOS

The Text Chat Accelerator Pack provides functionality you can add to your OpenTok applications that enables users to exchange text messages between mobile or browser-based devices.

Text Chat Accelerator Pack Examples

default custom

Configure, build and run the sample app

  1. Get values for API Key, Session ID, and Token. See Obtaining OpenTok Credentials for important information.

  2. Install CocoaPods as described in CocoaPods Getting Started. If you are only interested in the core part without UI component, you can use this pod 'OTTextChatAccelerator/Core'

  3. In Terminal, cd to your project directory and type pod install.

  4. Reopen your project in Xcode using the new *.xcworkspace file.

  5. Replace the following empty strings with the corresponding API Key, Session ID, and Token values:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        sharedSession = [[OTAcceleratorSession alloc] initWithOpenTokApiKey:@"apikey" sessionId:@"sessionid" token:@"token"];
        return YES;
    }
  6. Use Xcode to build and run the app on an iOS simulator or device.

  7. For testing text chat, we include a simple web app to make it easier: Browser-Demo-TextChat. Simply open it and replace the corresponding API Key, Session ID, and Token values. Then save and load it to the browser.

  8. You might want to run on other platforms:

Accelerator Textchat Javascript
Accelerator Textchat Android

Sample Codes

  • Passing the session

    - (OTAcceleratorSession *)sessionOfOTOneToOneCommunicator:(OTOneToOneCommunicator *)oneToOneCommunicator {
        return <#OTAcceleratorSession#>;
    }
  • Start signaling text chat data

    // we assume self owns a table tableView
    [self.textChat connectWithHandler:^(OTTextChatConnectionEventSignal signal, OTConnection *connection, NSError *error) {
        if (signal == OTTextChatConnectionEventSignalDidConnect) {
            NSLog(@"Text Chat starts");
        }
        else if (signal == OTTextChatConnectionEventSignalDidDisconnect) {
            NSLog(@"Text Chat stops");
        }
    } messageHandler:^(OTTextChatMessageEventSignal signal, OTTextMessage *message, NSError *error) {
        if (signal == OTTextChatMessageEventSignalDidSendMessage || signal == OTTextChatMessageEventSignalDidReceiveMessage) {
            if (!error) {
                [weakSelf.textMessages addObject:message];
                [weakSelf.tableView reloadData];
            }
        }
    }];
  • Stop signaling text chat data

    [self.textchat disconnect];

Obtaining OpenTok Credentials

To use OpenTok's framework you need a Session ID, Token, and API Key you can get these values at the OpenTok Developer Dashboard . For production deployment, you must generate the Session ID and Token values using one of the OpenTok Server SDKs.

JSON Requirements for Text Chat Signaling

The JSON used when using the OpenTok signaling API with the OpenTok Text Chat component describes the information used when submitting a chat message. This information includes the date, chat message text, sender alias, and sender ID. The JSON is formatted as shown in this example:

// var type = "text-chat"
{
    "sentOn" : 1462396461923.305,
    "text" : "Hi",
    "sender" : {
        "alias" : "Tokboxer",
        "id" : "16FEB40D-C09B-4491-A983-44677B7EBB3E"
    }
}

This formatted JSON is converted to a string, which is submitted to the OpenTok signaling API. For more information, see:

Development and Contributing

Interested in contributing? We ❤️ pull requests! See the Contribution guidelines.

Getting Help

We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:

Further Reading