'PubNubSwift Capture Receive Message

I'm working with PubNub. I have a standard WebRTC string being published with PubNub.

self.pubnub.publish(channel: self.channels[0], message: ["type": "offer", "sdp": sessionDesc.sdp]) { result in

Then the PubNub Listener listens to the Published signals on the Channel.

let listener = SubscriptionListener(queue: .main)
listener.didReceiveMessage = { message in
print("[Did Receive Message]: \(message)")
}
pubnub.add(listener)
pubnub.subscribe(to: channels, withPresence: true)

That works just fine, I get my SDP strings.

[Did Receive Message]: User 'pn-4D77E0B5-0145-ACAC-0366CB301ABC' sent '{"type":"offer","sdp":"v=0\r\no=- 4836309355638585269 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE audio video\r\na=msid-semantic: WMS ARDAMS\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 102 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:tKqW\r\na=ice-pwd:KNDM86R+JqsLqupw3J288kmJ\r\na=ice-options:trickle renomination\r\na=fingerprint:sha-256.....

My problem is that from within 'message'. How do I capture the 'type' and 'sdp' strings???

listener.didReceiveMessage = { message in
print("[Did Receive Message]: \(message)")
var type = message["type"] as? String <---- this does not work.
}

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source