The Signaling app is a very simple application meant to get a new developer started using the signaling features of OpenTok iOS SDK.
To use this application:
-
Follow the instructions in the Quick Start section of the main README file for this repository.
Among other things, you need to set values for the
kApiKey
,kSessionId
, andkToken
constants. See Obtaining OpenTok Credentials in the main README file for the repository. -
When you run the application, an OpenTok session is created . Signaling only needs OTConnection(s).
-
Run the app on a second client. You can do this by deploying the app to an iOS device and testing it in the simulator at the same time.
-
Signals are meant to transmit basic text data between participants in a session.
-
Signals don't have extensive chat like features (like emoji's etc).
-
Sending an signal using an session object as follows:
session.signal(withType: type , string: data, connection:c.getOTConnection(), error: nil)
or
session.signal(withType: type , string: data, connection:c.getOTConnection(), retryAfterReconnect: retryAfterConnect, error: nil)
retryAfterReconnect
default value is true
in the first call. The error case fails silently.
- Receiving a signal is done using OTSessionDelegate callback as follows:
func session(_ session: OTSession, receivedSignalType type: String?, from connection: OTConnection?, with string: String?) {
..
}
You just need to implement the above calls in your app.
- Valid Characters in a signal data is limited to
[^a-zA-Z0-9-_~\\s]
. If a non valid character is used , signal is not send. To get around this you can encode signal data withbase64
and decode it on other side. This way you can send emoji's for example. A sample code which extendsString
is provided below for reference:
extension String {
func fromBase64() -> String? {
guard let data = Data(base64Encoded: self) else {
return nil
}
return String(data: data, encoding: .ascii)
}
func toBase64() -> String {
return Data(self.utf8).base64EncodedString()
}
func isValidSignal() -> Bool {
return self.count <= 128 && self.range(of: "[^a-zA-Z0-9-_~\\s]", options: .regularExpression) == nil
}
...
}
- Tap on "Hello !!" sends a "Hello World" message to all connections.
- Tap on the Pen image leads to Form View (as shown below)