{"id":16222902,"url":"https://github.com/michael/talk","last_synced_at":"2025-03-19T11:31:47.848Z","repository":{"id":66446972,"uuid":"4620093","full_name":"michael/talk","owner":"michael","description":"Let's talk data. In realtime.","archived":false,"fork":false,"pushed_at":"2012-09-02T06:27:34.000Z","size":215,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-11T12:15:41.112Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michael.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-11T02:04:28.000Z","updated_at":"2019-08-13T15:04:21.000Z","dependencies_parsed_at":"2023-02-20T04:30:52.615Z","dependency_job_id":null,"html_url":"https://github.com/michael/talk","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael%2Ftalk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael%2Ftalk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael%2Ftalk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael%2Ftalk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michael","download_url":"https://codeload.github.com/michael/talk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221726984,"owners_count":16870713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T12:15:45.092Z","updated_at":"2024-10-27T20:01:23.501Z","avatar_url":"https://github.com/michael.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Substance Talk\n\nSubstance Talk is a protocol for exchanging data between multiple parties using the network. A party can be a web-browser, a web-server or any network program that can handle the Talk protocol. The communication is done by messages (expressed as JSON) and works in both directions. You can use any technology to implement a program that participates in a Substance Talk.\n\nThe idea is simple: Users should no longer worry about the implementation details of networking (such as HTTP headers etc.). People talk in messages and computers should too. Substance Talk is intended to be used with stateful connections, made possible by TCP sockets or websockets. It's being designed for realtime applications and distributed systems and kept as minimal as possible. Messages need to be specified in JSON notation.\n\n## Install\n\nFor Node:\n\n```\nnpm install talk\n```\n\nFor the browser:\n\n```html\n\u003cscript language=\"javascript\" src=\"talk.js\"/\u003e\n```\n\n## Usage\n\n\n### On the server\n\n```js\nvar Talk = require('talk');\nvar talk = new Talk.Server(3100);\n```\n\nHandling hello messages from the client\n\n```js\ntalk.handle('hello', function(line, message) {\n  console.log('Line '+ line.id +' says: \"'+message+'\"');\n});\n```\n\nSetting up a handler that does some computation and sends a response.\n\n```js\ntalk.handle('add', function(line, values, cb) {\n  var sum = 0;\n  values.forEach(function(val) { res += val; });\n  cb(null, sum);\n});\n```\n\n### On the client\n\n```js\nvar talk = new Talk.Client(\"ws://localhost:3100/\");\n```\n\nSay hello to the server. The first parameter is always the method, determining which handler gets called on the server. The second parameter contains the data being sent along with the message. The **payload** in networking jargon.\n\n```js\ntalk.send([\"hello\", \"I'm Tim\"]);\n```\n\nLet's have our server doing some work for us by calculating the sum of some numbers. \n\n```js\ntalk.send([\"add\", [1, 5, 7]], function(err, sum) {\n  console.log('And the result is: '+ sum);\n});\n```\n\nNote, `Talk.send` takes an optional callback parameter that is executed once the response arrives from the server. This is a crucial functionality you might need in almost any application but plain websockets don't give you that.\n\n## Maintaining State\n\nMaintaining state has always been one of the most challening things in computer science. So if you're going to use Websockets you should be aware that you need to spend some time with modelling your state data. Let me say this is crucial if you want do design a reliable system. No framework will do that job for you. Have a look at the implementation of the [Substance Library](https://github.com/substance/library/blob/master/src/agent.js) to see how we're maintaining state (=document editing sessions).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael%2Ftalk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichael%2Ftalk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael%2Ftalk/lists"}