Rocket.Chat.iOS icon indicating copy to clipboard operation
Rocket.Chat.iOS copied to clipboard

Meteor DDP connection

Open rafaelks opened this issue 11 years ago • 27 comments

The native app must connect with Meteor server via DDP protocol.

Here's a nice lib for iOS to make DDP connection: https://github.com/martijnwalraven/meteor-ios.

rafaelks avatar Aug 31 '15 21:08 rafaelks

@rodrigok Can you explain how the basic connection works?

Just to get started:

  1. Authentication
  2. List of Channels

rafaelks avatar Aug 31 '15 21:08 rafaelks

This one (https://github.com/boundsj/ObjectiveDDP) is actually more interesting, because it have authentication methods that follow Meteor pattern.

rafaelks avatar Aug 31 '15 22:08 rafaelks

Looks good, and quite a lot has been done, we just need look into library and maybe help improvement i saw that does not have to much commit last fill months, i already started looking into code, but i believe is a good start :+1:

felipeflorencio avatar Sep 01 '15 02:09 felipeflorencio

Yes I also had the one @rafaelks mentioned in mind... Haven't looked into either of them in much detail yet though..

Do you guys know why we should go with DDP and not use the REST APIs that Rocket.Chat provides? I know virtually nothing about DDP but I guess we get the updates without having to poll the REST APIs, right?

gsaslis avatar Sep 01 '15 05:09 gsaslis

One great advantage from approach of using DDP its her use of websocket, while REST will lead to always create connection for request, we will actually open multiple channels some times for do our requests, and depend of how many messages user are sending and receiving, this could cause overhead, sure thinking at big scale. Its basically whenever you made a request, say to download html, or an image, a port/socket was opened, data was transferred, and then it was closed. With socket this is prevented, actually, using socket they create like one channel to request and get response. Unlike HTTP, the socket that is connected to the server stays “open” for communication. That means data can be “pushed” to the browser in realtime on demand. While some think that this is bad for example because connection being open could lead to higher battery consumption, its wrong, actually using some "chat protocol" like web socket had advantages into this because not open, and close multiple times, and prevent system getting creating threads all the time. At market had other types of "chat protocols", but socket its well know and a good one i believe and of course meteor handle with.

I really like REST, but for purpose of "chat", this interface i believe we need go with socket :)

I don't know if helped, any other information will be helpful :)

felipeflorencio avatar Sep 01 '15 12:09 felipeflorencio

Hey, I'm the guy who did the REST API. And in my honest opinion - please don't use it ! :grin:

Let me better qualify ... please don't use it for the Native iOS app.

Meteor and DDP are what defines Rocket.Chat, otherwise we're just another kindamatter, slacky dak, let's yap, etc. We're talking about two orders of magnitude difference in terms of responsiveness, scalability, and efficiency.

It is a royal pain to adapt existing UIKit views, especially for UITableView - but result will be worth it. Some bleeding edge attempts to adapt:

http://componentkit.org/

https://www.objc.io/issues/22-scale/facebook/

Sing-Li avatar Sep 01 '15 12:09 Sing-Li

awesome! thanks so much for sharing this info @felipeflorencio / @Sing-Li !!

I guess we only need to decide on which ddp library to use then... Anyone have any thoughts to share on that?

gsaslis avatar Sep 01 '15 13:09 gsaslis

Thanks @felipeflorencio, @Sing-Li! :-)

So, I was studying both libs yesterday and seems that https://github.com/boundsj/ObjectiveDDP is better to us. Or maybe we could create a new lib based on DDP specification (sounds too crazy?).

rafaelks avatar Sep 01 '15 14:09 rafaelks

@rafaelks I liked your crazy idea :) all existing libs of DDP for iOS sucks, creating a new one using swift 2 would be better and likely a good experience, but you will need to port EJSON and MiniMongo too.

rodrigok avatar Sep 02 '15 01:09 rodrigok

Sounds good, i already saw a little about this lib ObjectiveDDP and need some improvements, if we started create a new one with just what we want. Would be great start new one :)

I tried create a issue to improvement for ObjectiveDDP for her OAuth connection that use NSURLConnection to improvement using NSURLSession but they said that if something that already work why change? So far i saw its not good we using a lib that don't want improvement her code.

felipeflorencio avatar Sep 02 '15 01:09 felipeflorencio

@felipeflorencio awesome! It will be a new, and better, lib for DDP. Meteor needs this. I tried to create one project with this existing libs with the help of @rafaelks and it was very difficult to implement even very simple things.

Maybe with Switft 2 and some NoSQL database for iOS the work could be easier.

@engelgabriel will talk to MDG to try to get some help :)

rodrigok avatar Sep 02 '15 01:09 rodrigok

Soon they say to start we begin :D would be great. But just one point, use Core Data would be better, with Core Data we could get better from a database like that Apple always do full support and improvement. I never implemented NoSQL database at my projects, but i actually work with one that was builded using SQLite that for mobile its almost the same idea or has the same restriction, some behavior points that we regret a lot is thread problems, zombie objects, always lock and we could get some issues, and when we tried update we always need do a huge efforts to get fit.

I don't know deep about NoSQL for sure, actually i'm a mobile guy, but tried implement another kinds of database as i saw so far was not a good idea guys ;)

felipeflorencio avatar Sep 02 '15 02:09 felipeflorencio

@felipeflorencio how hard is to use Core Data for data with no defined schema?

I listened a lot about https://realm.io/

rodrigok avatar Sep 02 '15 02:09 rodrigok

Actually its really easy, and if want get more easier we could use some lib like MagicalRecord, you could see here : https://github.com/magicalpanda/MagicalRecord. Look how easy is create entity.

For all these i really like more Realm.io, its a product that they want get improvements and its good. But for a open-source project i believe its not a good way for us

felipeflorencio avatar Sep 02 '15 02:09 felipeflorencio

wow -- isn't this a little out of scope for this project to build our own DDP impl?? I mean.. wouldn't that be putting this whole project on hold?

having said that, I've not tried using either of the 2 proposed libs, so I don't know how easy that would be.. will take a look as soon as possible...

gsaslis avatar Sep 02 '15 09:09 gsaslis

wow -- isn't this a little out of scope for this project to build our own DDP impl?? I mean.. wouldn't that be putting this whole project on hold?

It may not be in this case. We don't need everything offered by DDP, and @rodrigok knows intimately what we need and the optimal format or way to get at it.

Sing-Li avatar Sep 02 '15 18:09 Sing-Li

Honestly, I have no idea how much time it would take to us. But, the idea of writing a new Meteor client for iOS sounds interesting, mainly because currently implementations are written in Obj-C or in Swift but don't have mostly of methods that we need (1 & 2).

Of course we could get some of the current projects and contribute to, but since we're starting a complete new project in Swift 2, why not write a new DDP protocol wrapper in Swift 2 too? It actually could a complete separated project from this one, to be used by every other app that wants to use Meteor.

[1] - https://github.com/boundsj/ObjectiveDDP/blob/master/ObjectiveDDP/MeteorClient.m#L357-L371 [2] - https://github.com/martijnwalraven/meteor-ios: This one doesn't have the authentication methods, AFAIK.

rafaelks avatar Sep 02 '15 18:09 rafaelks

Hi guys, Just wondering if you've made any progress on your side with the whole DDP issue... ?

gsaslis avatar Sep 14 '15 08:09 gsaslis

I have not. IMHO if no one is working on that, we should start using an existent solution and then in a future, move to a made-in-home solution.

rafaelks avatar Sep 14 '15 11:09 rafaelks

@rafaelks ok - sounds like a plan!

( i'm afraid I won't have a chance to look into the ddp speciifcs myself till next week though... : / )

gsaslis avatar Sep 15 '15 21:09 gsaslis