Upgrade to Pro — share decks privately, control downloads, hide ads and more …

全てのブラウザがWebRTCに対応した今、アプリでWebRTCを実装する意味はあるのか

taminif
August 25, 2017

 全てのブラウザがWebRTCに対応した今、アプリでWebRTCを実装する意味はあるのか

WebRTC Meetup Osaka #1の発表資料です。

taminif

August 25, 2017
Tweet

More Decks by taminif

Other Decks in Programming

Transcript

  1. ϒϥ΢βରԠঢ়گ • Chrome, FireFox, Opera͸ରԠࡁΈ • AndroidͷChromeͰ΋ಈ͖·͢ • Safari͸͜ͷळͷSafari11ͰରԠ༧ఆ •

    Edge͸य़ʹग़ͨCreators UpdateͰରԠ͞Ε ͍ͯΔʢͨͩ͠ಈ͖͸ඍົʣ IE?ରԠͯ͠ΔΘ͚ͳ͍΍Μ
  2. API KeyΛ࢖༻ͯ͠Πϯελ ϯεΛ࡞੒͠·͢ let options: SKWPeerOption = SKWPeerOption.init() options.key =

    "79f76a5d-b1b9-4c4f-9e0d-d5713edd9e31" options.domain = "XXXX.XXXX.ne.jp" peer = SKWPeer.init(options: options) peer?.on(SKWPeerEventEnum.PEER_EVENT_OPEN, callback: {(obj) -> Void in if let ownId = obj as? String { self.ownId = ownId } else { print("error") } }) ͜ͷQFFSΦϒδΣΫτΛ ࢖ͬͯ$POOFDUJPOΛ࡞ Γ·͢ ಉҰͷ"1*,FZͰ࡞੒͞ ΕͨQFFSΦϒδΣΫτؒ Ͱ௨৴͕Ͱ͖·͢ɻ
  3. API Keyͷ࢖͍ํ͸JS/iOS/ Androidશͯಉ͡Ͱ͢ // Connect to PeerJS, have server assign

    an ID instead of providing one // Showing off some of the configs available with PeerJS :). var peer = new Peer({ // Set API key for cloud server (you don't need this if you're running your // own. key: '79f76a5d-b1b9-4c4f-9e0d-d5713edd9e31', // Set highest debug level (log everything!). debug: 3, // Set a logging function: logFunction: function() { var copy = Array.prototype.slice.call(arguments).join(' '); $('.log').append(copy + '<br>'); } }); // Show this peer's ID. peer.on('open', function(id){ $('#pid').text(id); }); (ྫ)JSͷ৔߹ʢαϯϓϧͦͷ··࢖༻ʣ
  4. dataConnectionͷੜ੒ peer?.on(SKWPeerEventEnum.PEER_EVENT_CONNECTION, callback: {(obj) -> Void in self.dataConnection = obj

    as? SKWDataConnection self.setDataConnection() }) let options: SKWConnectOption = SKWConnectOption.init() options.label = "file" self.dataConnection = peer.connect(withId: connectId, options: options) self.setDataConnection() ૬ख͔Βͷ઀ଓΛ଴ͭ৔߹ ࣗ෼͔Β઀ଓ͢Δ৔߹
  5. dataConnectionͷΠϕϯτ؅ཧ dataConnection.on(SKWDataConnectionEventEnum.DATACONNECTION_EVENT_OP EN, callback: {(obj) -> Void in print(obj) })

    dataConnection.on(SKWDataConnectionEventEnum.DATACONNECTION_EVENT_DA TA, callback: {(obj) -> Void in print(obj) }) dataConnection.on(SKWDataConnectionEventEnum.DATACONNECTION_EVENT_CL OSE, callback: {(obj) -> Void in print(obj) }) dataConnection.on(SKWDataConnectionEventEnum.DATACONNECTION_EVENT_ER ROR, callback: {(obj) -> Void in print(obj) }) ઀ଓཱ͕֬͞Εͨ࣌ σʔλΛड৴ͨ࣌͠ ઀ଓ͕ด͡ΒΕͨ࣌ Τϥʔ͕ൃੜͨ࣌͠
  6. WebRTC͋·Γؔ܎ͳ͍ͷͰ ͞Βͬͱ func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer:

    CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) { if let photoSampleBuffer = photoSampleBuffer { // JPEGܗࣜͰը૾σʔλΛऔಘ let photoData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: photoSampleBuffer, previewPhotoSampleBuffer: previewPhotoSampleBuffer) let image = UIImage(data: photoData!) let imageData = UIImageJPEGRepresentation(image!, 1) let result = self.dataConnection?.send(imageData as! NSObject) print(result) } else { print(error) } } σʔλΛૹ৴͢Δ࣌ͷॲཧ ΦϒδΣΫτܕʹ͢Δඞཁ͕͋Γ·͢