Search code examples
swiftswift3opentok

sending a message using openTok


I am trying to create a chat app using openTok(Swift 3) but having a issue to send messages to other users in the session. I do receive the connection of other users but unable to send the message. Instead of sending a message ,I, myself receives it.I tried to send it to a single person as follow:

func sendMessage() {
    session = OTSession(apiKey: ApiKey, sessionId: SessionID, delegate: self)
    session?.signal(withType: "Chat", string: "Hi", connection: (session?.connection)!, retryAfterReconnect: true, error: nil)
}

when i tried to send to all users in the session then it says 'Ambiguous reference to member session': please see image

also when i check function source (clicked function holding down command key) then it goes to NSLock.h in Foundation Framework

now i don't know where to go or what to do!


Solution

  • Indeed, @wobbals is correct. First of all, you have to call open func connect(withToken token: String!, error: AutoreleasingUnsafeMutablePointer<OTError?>!) and receive public func sessionDidConnect(_ session: OTSession!) afterwards in order to enable the session object to send signals. Please do remember to record the error so you will have some ideas what happen if failure.

    From the documentation, the connected session will broadcast to every connection, including yourself, if you pass nil to the connection parameter. I believe this line session?.signal(withType: "Chat", string: "Hi", connection: (session?.connection)!, retryAfterReconnect: true, error: nil) will crash your application because of unwrapping a nil object due to the nil value of session?.connection if session is not connected.

    Just a side note, it's actually confused here if you post code and also an image. We don't know which is your actual problem is. But, they both have obvious issues.