Merken

ActionCable for Not-Another-Chat-App-Please

Zitierlink des Filmsegments
Embed Code

Automatisierte Medienanalyse

Beta
Erkannte Entitäten
Sprachtranskript
thank God it and the but the the the the the floor of to the what is new in rails 5 tracked by which to really proud to be part of how I'm excited for all other talks today so I think this is of a really cool really so let's dive into a cable boxes also this was the 1st cable parts of I resource and what it's got cable and 0 if any of you are old enough to have seen 1 of these things so but like this would sit and connects to you your to achieving and you'd like be like OK to get 33 I finance and that is that of some concept they were talking about obviously for this presentation I made several high quality 8 bit part not to bit not for of the diagrams that this presentation you're welcome in advance so here we see or intrepid user connecting the 2 rails through or I yet so again you I'm pretty good of so how can actually table sort of change of self the so what readers were talking about the history of action cable and WebSockets which are valid and what is what it's not I will talk about building blocks like what actually what code is there you use and then some patterns also that played strategies have actually make use this today my name is just Wal-Mart you chairman of i and j will launch water in the get out of the the the questions comments on the stock of inward have time to units so that treaty on and do my best so the chance of so I found that the best way to look for work that changes the word and that the were take place is to look back in the scene where assume we stand in the March of time so let's start at r FI refresh war like our command or so in general like this is how we would of the page for a lot of times so like checking your e-mail was frustrating you had a clicker read French fleet of and then you make sure the like your to made of storage didn't get taken up by semi by some you would 300 by 300 the and the had occultist texting wasn't really hitting at you to call your friend we like check your e-mail it is full kids today with your gigs upon its abundance of storage astonished so other matter wanted you to get a page to update itself maybe they just have like auto refresh so you have like a meta tag that would say hey refresh yourself every 3 to 10 seconds so tragic words it did this for for a long time i think still does so incensed sites were being paid by the ad impressions like this is a pretty good story you just leave your site that were just refresh refreshing fresh otherwise not optimal the but this would be without the mic that work so by the time at like 2 thousand to 2003 rope came along so we want better and so on we have fully polling 0 would be in that time like gene right like Gmail came out and did it take you back to new messages we did not take page it's and at the time of rule of and this is in 2002 by 2012 excuse me of a d takes a campfire to those days still uses at 3 2nd called so channels was the poster boy for WebSockets friends from now that's 2012 times have changed I'm glad that we can move on but this was pictures of you this is is a polling remains a great way to make your app him if you don't require subsecond responses light updates in base camp or pole so like this works on a very large set of websites where you can just have it like every 3 seconds Sprechmann stuff so far there or apps that don't need with sub-second responses having year jet JS whole for changes on interview ball is like an extremely good idea many services so this can be what that looks like a you japery pops up is a set animal make an AJAX recall every 3 seconds and sort of set it and forget it but then you to websites which were so great now the so I 1st solved like WebSockets used with pusher of the here and make everything very easy like they took care of everything so what the process an image background and then post pushes API when you're done in your friend and listen to pusher and like updated when was done so this came out as far as I can tell by 64 55 and thousand 11 it says basically it's two-way communication between the client and server and that the remote host has to opt into the communication that it can't just where's HTTP calls just error taken right but the client has to request a WebSocket server has to say yes so some examples socket that I ILO make things pretty simple node land to push updates from the server after the point patterns of very 11 built a pretty sweet fake stock market of you played with this and that it is pretty sweet so it sends trade valve the websites or you can constantly ask the an API call like which like do you have any new traits that have been made the but the thing is like you'd have to do that on a loop is really traits and is is a really Trager making election every time of in when you're trying to high-frequency trading which is what sort of it's all about 0 you want the you want to get at the trade as soon as it possibly can and so connected via WebSockets was a way that you can actually get it almost as it happens rather than on making a call in in the so the trouble is how conservative trackable these connections like scaling up in a big server can also work language which like a lecture and others like it but what about a dear friend Rudi if every connection like lives in there's study an object that's like listening for connections from server to client from client to server like that has to be taken up in memory and Ruby loads of memory so you're probably like I'm certain that 2 thousand connections let alone 2 million connections so with with Ruby with rails there's gotta be a story about scaling how not scaling up and spoiler alert there is so is the future just real-time probably not I doubt that like we're going to default to building every feature with actionable but I think it had sort of possessed and fun and and really fast updates like for certain apps that require that low latency website that is how I would describe outreach also my cluster the so it's take a look at
what action is and what's not so if we know when possible words are but we also know where the Austin we can decide if it fits in our toolbox so 1st let's start with the what it's not in general of it's just solvable it'll make everything like super fantastic great also source so let's what it's not so it's very much made to work inside of rights of I could see a future of words lifted out before I see were not there yet I don't consider this a bad but it does sort of want to be in a request or it wants to connect with the with the controller it wants to be in rates that's fine and it's not like gibbon NPM install action cable so also not necessarily a step forward for rails and the more jobs for innovation like there is jobs script here by like the it's I saw this and was like I think this makes sense it's not it is just a feature it's the next Jabal boulder that's the next Turbo links it's not the next acid pipeline it's not the next active records it's just a feature so stop on what it is so it's a solid feature like it works it's fine it adds value to your app I don't think it needs to be any more than this but this is sort of the scope it's a nice feature to have 4 rails out so like Turbo responses heritable links and JavaScript responses but it's a little like snap at it's a way to make it faster like there is a certain while factor where you've got like 2 windows up and make a change on 1 like propagates to the other like people so like wow that's who it's also easy and fun the much like across a so why no chance like why had I specifically police come here and say when I talk about so when I came up with the idea for this talk of so much right like I was dreading the top that I might here if I attended but I think it be about chatting which he uses of maybe like intercom a combat I O style immigration but there's so much more that we can do with sockets because chapter the hello world of websites they don't add to me like they don't have anything like the or features where like if it's a chat you probably want a check but I just add in chapter to an app doesn't make it possible but and so as we show people i you can use action table here's a chat it's but but that's not where the where the real value propositions the because most apps don't need chat between 2 different users like Facebook picture never such a network may be but I employee when you go when you try this out don't just add chat to your existing acts as a way to check the action level but some have to do need the between the server and the client but if were building on social apps there's wins on what action have guessed so so what is this summer 1 as I see it is collaboration so this can be as complete as a big Trello style of where were both editing the same documents and forward or something adds a card and it and it shows up on my picture the or maybe a price changes on a website inventory changes stuff like that would be nice if I'm viewing everything if it did update rather than later on another page load use case number 2 asynchronous tasks so if you implement task that the server due a like that's all new data from a 3rd party or something of media some like created PDF from invoice likely throw on an action job and pole for 1 that's complete it's not easy it's not rocket science here but it's doable but actually a mechanic that from that so the 1st action table data so again more with the history an analytical and promised it's a last year action cable was announced as vapor were but it was announced that the diagram but no code this is the diagram the now not too much later in July of 2015 we got a 1st look at them and that's only a couple months so like as far as like where the existence of that's not all that long it was a non rails experience now it was only version 0 . 0 but like trying it out was a little bit rough so are no generators no deployment story no standalone known in Abidjan and again this is version 0 nm and hearing complaining about it only I was able to get it to work it was a pain like sort of a diving into the source code pain to try and figure stuff out and that's not necessarily the radio this way so I'm glad existed I bring this up to say that if you try to them and didn't like it now is a much better experience the causal there but it's got an action which is so the current beta version 5 . 0 . 0 beta 3 which seeks across rails versions was released and there were 2 dozen 16 this and I was so what to start so it made all the things that I like enumerated above for this talk like do this don't do this if you want unauthenticated users if demand much that's this it made them all just go away was great and I was happy this so finally some code a of building blocks so the
models so what makes actually cable action table the 4 distinct modules so the 1st yes so the 1st one is the table so this is the the actual connection from client to server so of but it's what is connected to so it's like it lives on messages go back and forth without having to be connected so the that channel but I to get a cable that's natural connection that you got a channel the channel is the thing is sort of a rule and it's it's what you listen for events so a channel is on the rail side uh it has a dream name they can be like all products that work in the scope down to specific user like part underscore like that uses ID is sending information out from rails through the channel to play and then you have a subscription subscriptions on the client side generally this is just our script doesn't have to be but action cables start a script and it's a quasi listening you receive data from from the server decided to each of these so the cable the actual connection of my examples in is are going to be in job script not script so you can easily make these go to copy at like test that coffee there these amount of just that of so that we do here is we require the action of the library all the channels and we create a big AC object the the doesn't exist and then we slide the table on onto the adapt global object so in general like this is what exists after cable on jobs sigh on the rail side we tell it's process sockets in process so this is a C at slashed people this is sort of the easy way to do it on the slash cables configurable but this is sort of assumed to be the convention that use that's the actual connection between the 2 so let's look at channels on the rail side a channel is like a controller so it groups sort of like 2 years together you might have a product's controller maybe the inbox uh which dream like specific to that user of updates on the thing about this as like on Facebook maybe you've got a stream of the rightful like all your updates of what people do and then maybe you've got a stream in the middle for your use the so they group together so each channel has a connection the the and it inherits from application connection so this is very much a controller inherits the application control so here's where you would tell that this connection that you have a current user objects so identified by current user enables you to use this later on it enables you to to be able to say that your channel is only for a specific user and 0 1 7 year we see what happens when the channels connected to so when the channel was connected we find the user so user defined by the ID of cookies that signed user so I will come back to this a little bit but notice that it's cookies that's I'm not session idea so you don't have a section should evidence but since you have cookies this could be in application trawler using like pasta password which might be here so you would say online non cookies that signed user really is the user that and an online 5 user find by adding computer science so you switch from a session of user ID typically is assigned to the I have a device example later for like a 90 per cent of you prove wondering how to do this with the vise and so I I just want to come the sum of broadcasting so here I am using an action job to broadcast a message to a job scripture that'll send it up to that point so line 6 shows how to send it out so action table that server broadcast and then you give it a streaming and perhaps so that cash would be the data that's can be set up that half you'll send it out as a half it'll be received later in job script as just a jobs about so this can be done anywhere great tasks action jobs controllers model called artists like anywhere in rails has the ability to send out broadcasts just will so also here I in I'm doing that actually controller . render of which is super also think we'll look back and see this is a very cool feature will go into that a little bit finally get a subscription that's the job script was so when you create a subscription it listens for all broadcasts for that channel so when the server broadcasts a message it worse it calls the received function and that's where you get your data so after product is equal to cable subscriptions create and you get connected if 1 of a lot that disconnected if like that and then received received is sort of magic function like that's what you need to call that's when I broadcast from rails up to John script that's what it cost and you can do whatever you want with that they so here it's like data product that idea that what you can do whatever you needed to with us here and saying let's find a product with the data productivity of the energy replaced with the template so in this example rails and sending of the updated template for that product and it's in remember right on top of the so let's walk through a standard action cable interaction will start on the client side is so by requiring action table cable cables to the real thing the browser then upgrades the cable connection to WebSockets connection when the subscription subscribe to the connection connects the and then to start listening for updates you create a subscription with the received function that's what it's called so you can have many subscriptions and like many different places so what I mean by that is like actor channel applicable that channel is this global thing the so anywhere in jobs that you can access so it could be your standard J. query style like listen for the event of war it could be in In react like on the component and now it could be an angular it could be an amber on so controller like any of these things can create a subscription and start using so the subscription calls received data when subscription receives the data this is the Tron Dolores alone getting plus other patterns like how we might set up for specific scenario 1st will talk about data updates so this is but basically call collaborations but we can keep data in sync across tabs and I'm in sync I'm certain sorry so if you're looking at a pretty sweet browser set up step forwards adds up in the right top right is be part but that's that's part of it were selling tennis balls of those tennis balls so that's your ad hoc buttons telling a pretty good but we're looking at like for task
because the middle to are like on the site of edges but all Amazon and other research cannot be like Open Data Open Data Open Data Open new of that like all of these open that I can that I can put so if we add the cart context story there's no 1 item in cart but what about taxes it's typically back on the right it's typically sort of it was it'll show whatever was on that page as it loaded but not update itself even though tab 3 updated it's not a huge thing but what could we do to make this experiencing slightly better so after the update happens like in controller were job you would broadcast a message the message can be data or it can be a real rails rendered template partial for you to update so this is the after application that the so when I heard about application controller Govender was basically a and seeing the dance of joy so I'm 1 of this for so long the use case that I have a word is like creating reports so each month we wanna create reports you whenever liberate task of and I wanna be able to use Wikipedia to to take h 2 known converted loans but it's not in a request but there is no request at that point so you so I had to do something like we hear things may and to like make that work but now it's easy you just vendor of an entire like a partial or pages hand what locals you think this partial should have and they can be the same partial that you would use if you like rendering apart rendering of like a list of products I think it's really lost years I you could send out a new course partial to current user only so you would broadcasts a cart underscore current underscore user but ID so that would be scope to just that uses but it would only go out on channels where that subscriber read or that user so it's not like them that cable has all of the messages only has messages that it's actually substructures here's the channel set up the but that would set up the stream so the channel would have subscribing States streamed from cart underscore proteins both of these events on the rail side so you've got broadcast to a channel and then job script listens for that message so at cable subscriptions create cart underscore the current is ready he receives the data replaces up at about laptops receptors but we can also sort of took into existing jobs to libraries so maybe like you change a graph of the 2 options can actually cable be used to send messages to the server that something happened find yes it can so if you want send a message to the server and then out to other clients here is an example for you so the example of that is the conditional 5 slides presented mode so imagine that this is like reveal JS and were looking at so of course you'd be looking at sort of like a read-only state i'd have the ability to change the change the slides and so what we would do is you add an event was so you had an event listener to the change that's reveal specific so all this is predicated on your jobs that libraries having books that you can teII into by what gets sent from client to server when you say after slides notification that advanced slide and the standards and the so the slides notification that's the channel and you got a channel method on advanced slides and then you send the data so after slides notification that events like so advanced slide is the method the job a script will call to tell rails that something so here is a habitat slides innovation is that act tables subtractions so this is setting up a subscription to previous was using it and so we say advanced life so that's the function that we call Music app that slides and fission that advanced life this does this duck performs slides data back on the rails side where the slides channel so this streams from slides that slides Street is the name of of it so earlier the so line 6 here we perform performed on slides the Senate the data that slides becomes line 3 year stream from slides and calls the 6 slides that so that what is what comes in from jobs that back to rates so there's the broadcasting out and then the receiving message back so 1 6 years slides of data where you understand say if current user . admin had been then actually table server broadcasts like broadcast it out again so it's interesting that this is messages go from client to server it's not peer-to-peer so like this makes sense when we think about it but if I wanted if we were all on a server right and I want to send a broadcast message up to all of you I would not send it directly to you I was sent to the server the server and vice-versa as you work like that but it's the so some collaboration to travel cards like that's sort of what it would be little tracker also the cards but don't get they do anything where it sort of complete with a yes no you can merge with traps the items that on and then it updates all the other users during so this is in the way that if if I like click and merge it's going to other people viewing that page will remove the ability to march I think that that's the type of thing that we can very easily get huge wins out of what action can finally cygnus tasks so let's imagine we have a system uh where we use like mechanized to go out and that's the latest data this city quite a bit of time so let's throw in action cable job for national the so the 1st thing we do is we generate a channel so the channel is and how many streams based on like a UUID so each task that we do have stream from the JSC posted up given it the year ID that defines this job you would then create a subscription on extreme with that you're ready for when messages come back from rights maybe you have the site search job that performs search with you ready so you have a stream that broadcasting I'm starting and then so have you do all the stuff and then actually table server broadcast stream that it's complete and along the map that template the now it's gotten discussed chat a red that this this concept of i message on iPhones lock-in and that people who really love seeing the bubble like with people attacking that makes it feel sort of instant 2 connected to someone like there's an actual person that's actually typing right now the so the the come back so
as he is and sorry touched that this in modern romance so yes another he saw the bubble but then nothing but the publicist went away after a while we never got a reply in Saturday's through these but there's a sort of emotional thing with us but it's a limited so you could listen for the key of event on its exterior and then tell the server that you're taking in of the church typing in the conversation between you and that was what then when messages sent you would stop the bubble and render the message that and maybe you would handle if you haven't typed and 1 the and attract a 7 foot so in that mode is basically easy mode think of it like you psychic not In light of its so you're not doing psychic it's just 1 it works but scalability is a thing so it can be done with only 1 server and no rescue psychic like you can just say that everything is in line everything is a sink so you tell it might you doctor is a city and then like in Fig cable that can all facing Casey Casey everything is done using so that's just press it connects to slash cable the real server and generally can work pretty well but if you've got more than 1 server like you got multiple Dino's or whatever but they wanna use rats so you want I have a server server S inredis will keep it is otherwise everything system be in memory on each server that this if I connect to 1 server that is a connection you connect another than now we have to have some way that I can actually pass messages back and forth recipe that channel
basically Hartmann is slightly more involved the same scale as sort of moving from a to psychic you connect your readers you gotta have an actual of like sockets stuff domain that I 0 you figure where it is so it knows how to connect war with the person so are green person connects trails again you're welcome when you broadcasted sends a message to read action cable is listening for that and then actually able sends it back up
so quick like and options so 1 obvious messages like I don't think we know yet what this story sounds but I think we have to think about the idea that if understanding of the update of the update and you miss some messages u go offline like what is that look like in a physical like it's a physical network connection to somewhere in the world so you wanna use action job don't line like just broadcast out in your controller because it would have to send like somewhere out along world don't wait for that also know session only cookies so here is revised version you're welcome if you configure your request origins to allow or disallow people to be able to connect to you I found that don't leave a trailing slash in the in the host because it will not work and finally the configured died table that Gamal default setup of this is what gets generated the production of your Operators's local host so you'll need to change that so where where do you go from here so I get a simple example that you can look at the Joao slash inventory cable there is also action cable examples these are very good there's documentation on this you work out I'm but so action can is part of the rail standard just like action bionic give some many thanks so thanks to DHH for having the idea announcing it making it happen like this is very cool the 42 + contributors on the actionable project you also and thanks to the and Erica Kane for me to come you spend spend today with the so we're hiring developers across the US that 1 how to teach make the world better change lives improve diversity so interested to any kind of and general thank you very much thank you thank you if my this this this my
Bit
Prozess <Physik>
Punkt
Formale Sprache
Computeranimation
Homepage
Client
Einheit <Mathematik>
Mustersprache
E-Mail
App <Programm>
Güte der Anpassung
Gebäude <Mathematik>
Systemaufruf
p-Block
Hoax
Meta-Tag
Menge
Rechter Winkel
Festspeicher
Grundsätze ordnungsmäßiger Datenverarbeitung
Strategisches Spiel
Server
Socket
Message-Passing
Tabelle <Informatik>
Fehlermeldung
Telekommunikation
Web Site
Quader
Wasserdampftafel
Gruppenoperation
Mathematisierung
Kombinatorische Gruppentheorie
Code
Demoszene <Programmierung>
Loop
Endogene Variable
Speicher <Informatik>
Bildgebendes Verfahren
Einfach zusammenhängender Raum
Zwei
Schlussregel
Quick-Sort
Objekt <Kategorie>
Diagramm
Last
Mereologie
Wort <Informatik>
Bit
Atomarität <Informatik>
Ausbreitungsfunktion
Versionsverwaltung
Computeranimation
Übergang
Homepage
Prozess <Informatik>
Existenzsatz
Bildschirmfenster
Skript <Programm>
App <Programm>
Vervollständigung <Mathematik>
Datennetz
Physikalischer Effekt
Gebäude <Mathematik>
Strömungsrichtung
Turbo-Code
Dichte <Stochastik>
Quellcode
p-Block
Bitrate
Teilbarkeit
Polstelle
Generator <Informatik>
Kollaboration <Informatik>
Rechter Winkel
Server
Tabelle <Informatik>
Subtraktion
Facebook
Web Site
Gruppenoperation
Mathematisierung
Zahlenbereich
Code
Socket-Schnittstelle
Task
Datensatz
Reelle Zahl
Endogene Variable
Installation <Informatik>
Drei
Betafunktion
Aussage <Mathematik>
Binder <Informatik>
Quick-Sort
Chipkarte
Diagramm
Last
Hypermedia
Gamecontroller
Wort <Informatik>
Dampf
Umsetzung <Informatik>
Bit
Punkt
Gewichtete Summe
Prozess <Physik>
Browser
Gruppenkeim
Kartesische Koordinaten
Synchronisierung
Computeranimation
Homepage
Streaming <Kommunikationstechnik>
Client
Prozess <Informatik>
Gruppe <Mathematik>
Mustersprache
Volumenvisualisierung
Skript <Programm>
E-Mail
Gerade
Umwandlungsenthalpie
Softwaretest
App <Programm>
ATM
Lineares Funktional
Vervollständigung <Mathematik>
Pay-TV
Template
Stellenring
Abfrage
Strömungsrichtung
Kontextbezogenes System
Bitrate
Biprodukt
Ereignishorizont
Konfiguration <Informatik>
Rechenschieber
Kollaboration <Informatik>
Mechatronik
Rechter Winkel
Server
Garbentheorie
Information
Extreme programming
Message-Passing
Aggregatzustand
Standardabweichung
Tabelle <Informatik>
Web Site
Subtraktion
Facebook
Mathematisierung
Gruppenoperation
Entscheidungsmodell
Interaktives Fernsehen
Broadcastingverfahren
Socket-Schnittstelle
Task
Informationsmodellierung
Notebook-Computer
Datentyp
Programmbibliothek
Passwort
Zusammenhängender Graph
Informatik
Konfigurationsraum
Einfach zusammenhängender Raum
Videospiel
Graph
Anwendungsspezifischer Prozessor
Systemverwaltung
Mailing-Liste
Schlussregel
Physikalisches System
Modul
Quick-Sort
Chipkarte
Mapping <Computergraphik>
Objekt <Kategorie>
Energiedichte
Offene Menge
ROM <Informatik>
Mereologie
Gamecontroller
Cookie <Internet>
Wort <Informatik>
Verkehrsinformation
Einfach zusammenhängender Raum
ATM
Umsetzung <Informatik>
Skalierbarkeit
Festspeicher
Datentyp
Server
Physikalisches System
Schlüsselverwaltung
Ereignishorizont
Quick-Sort
Gerade
Gerichteter Graph
Message-Passing
Computeranimation
Mathematisierung
Physikalismus
Gruppenoperation
Versionsverwaltung
Socket-Schnittstelle
Computeranimation
Domain-Name
Prozess <Informatik>
Softwareentwickler
Default
Gerade
Einfach zusammenhängender Raum
Zentrische Streckung
Nichtlinearer Operator
Datennetz
Güte der Anpassung
Stellenring
Biprodukt
Quick-Sort
Konfiguration <Informatik>
Mereologie
Gamecontroller
Cookie <Internet>
Projektive Ebene
Message-Passing
Lesen <Datenverarbeitung>
Standardabweichung
Tabelle <Informatik>

Metadaten

Formale Metadaten

Titel ActionCable for Not-Another-Chat-App-Please
Serientitel RailsConf 2016
Teil 59
Anzahl der Teile 89
Autor Wolgamott, Jesse
Lizenz CC-Namensnennung - Weitergabe unter gleichen Bedingungen 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben.
DOI 10.5446/31495
Herausgeber Confreaks, LLC
Erscheinungsjahr 2016
Sprache Englisch

Inhaltliche Metadaten

Fachgebiet Informatik
Abstract RealTime updates using WebSockets are so-hot-right-now, and Rails 5 introduces ActionCable to let the server talk to the browser. Usually, this is shown as a Chat application -- but very few services actually use chats. Instead, Rails Apps want to be able to update pages with new inventory information, additional products, progress bars, and the rare notification. How can we make this happen in the real world? How can we handle this for unauthenticated users? How can we deploy this?

Ähnliche Filme

Loading...