{"id":21296948,"url":"https://github.com/reddec/chrome","last_synced_at":"2025-03-15T17:27:45.300Z","repository":{"id":21165444,"uuid":"24468771","full_name":"reddec/chrome","owner":"reddec","description":"Wrapper of Chrome Packaged App API in CoffeeScript","archived":false,"fork":false,"pushed_at":"2014-09-27T18:31:20.000Z","size":184,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-09T00:06:38.929Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reddec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-25T17:50:31.000Z","updated_at":"2014-09-29T12:51:48.000Z","dependencies_parsed_at":"2022-08-22T18:10:19.804Z","dependency_job_id":null,"html_url":"https://github.com/reddec/chrome","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fchrome","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fchrome/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fchrome/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fchrome/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reddec","download_url":"https://codeload.github.com/reddec/chrome/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243765048,"owners_count":20344526,"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-11-21T14:31:16.438Z","updated_at":"2025-03-15T17:27:45.193Z","avatar_url":"https://github.com/reddec.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Wrapper of Chrome Packaged API in OOP patterns in CoffeeScript\n-------\n\n* Author: RedDec\n* Created: 25 Sep 2014\n\nJavaScript object: ` window.rdd `\n\n### Table of contents\n\n* Network\n  * [TCP client](#tcpsocket)\n  * [TCP server](#tcpserver)\n  * [UDP socket](#udpsocket)\n\n\n# TcpSocket\n\nJavaScript: ` window.rdd.TcpSocket `\n\n\n[Original API](https://developer.chrome.com/apps/sockets_tcp)\n\n## Example\n\n```coffeescript\nTcpSocket.create (sock)-\u003e\n  sock.on 'data', (data)-\u003e\n    console.log 'Chunk', ab2str8(data)\n  sock.on 'connect', ()-\u003e\n    console.log 'Connected'\n    sock.send 'Hello world!'\n  sock.on 'close', ()-\u003e\n    console.log 'Closed'\n  sock.on 'error', (code, err, from)-\u003e\n    console.log 'ERROR:', from, code, err\n  sock.connect '127.0.0.1', 3000\n```\n\n## Events\n\n\n* `connect` [TcpSocket] - socket established connection to remote host\n* `disconnect` [TcpSocket] - socket disconnected from remote host\n* `close` [TcpSocket] - socket closed\n* `data` [ArrayBuffer] - data read from socket\n* `error` [code, error, sendet] - raised error\n\n## API\n\n\n### [static] create\n\n``` create(done) ```\n\nCreate new TcpSocket\n\n* `done` [function(TcpSocket)] - Done callback\n\n### [constructor]\n\n``` TcpSocket(@socketId) ```\n\nCreate new instance of TcpSocket\n\n* `socketId` [Integer] - Socket file descriptor\n\nPublic variables:\n\n* `paused` [boolean] - is socket disabled for receiving messages\n* `closed` [boolean] - has been socket closed\n* `connected` [boolean] - is socket connected to peer\n\n### pause\n\n``` pause(state, done) ```\n\nEnables or disables the application from receiving messages from its peer.\nAutomatically sets to true when connection established.\n\n* `state` [boolean] - Pause state\n* `done` [function(TcpSocket)] - Done callback\n\n\n### close\n\n``` close(done) ```\n\nClose TcpSocket. Emits 'disconnect' and 'close' events. Do nothing if not connected, but callback will be invoked.\n\n* `done` [function(TcpSocket)] - Done callback\n\n### send\n\n``` send(data, done) ```\n\nSend data to peer. Emits 'error' if socket is not connected.\n\n* `data` [ArrayBuffer | Object] - Message. Type of messages and end view depends of `IOC`\n* `done` [function(info)] - Done callback\n\n### connect\n\n``` connect(host, port, done) ```\n\nConnect to remote address. Emits 'error' if connection failed. Emits 'connect' if connection established.\n\n* `host` [string] - remote domain or ip\n* `port` [integer] - remote port number\n* `done` [function(info)]- Done callback if connected\n\n\n### disconnect\n\n``` disconnect(done) ```\n\nShutdown connection. Emits 'error' if socket is not connected.\nEmits 'disconnect' if connection shutdowned.\n\n* `done` [function(TcpSocket)]- Done callback\n\n### info\n\n``` info(done) ```\n\nGet socket info. Emits 'error' if socket not connected.\n\n* `done` [function(info)]- Done callback\n\nInfo (https://developer.chrome.com/apps/sockets_tcp#type-SocketInfo):\n\n* socketId [integer]\n* localAddress [string]\n* localPort [integer]\n* peerAddress [string]\n* peerPort [integer]\n* ...\n\n----\n\n\n# TcpServer\n\nJavaScript: ` window.rdd.TcpServer `\n\n[Original API](https://developer.chrome.com/apps/sockets_tcpServer)\n\n\n## Example\n\nCoffeeScript:\n\n```coffeescript\n# Echo server\nTcpServer.create (server)=\u003e\n\n  server.on 'accept', (sock)=\u003e\n    console.log 'Accept'\n\n    sock.on 'data', (data)=\u003e\n      sock.send data\n    sock.on 'close', ()=\u003e\n      console.log('Client closed')\n    sock.pause false, ()=\u003e\n      console.log 'Reading...'\n\n  server.on 'listen', ()=\u003e\n    console.log 'Listen'\n\n  server.on 'error', (code, err, from)-\u003e\n    console.log 'Err', code, err, from\n\n  server.listen '0.0.0.0', 3001\n```\n\nJavaScript:\n\n```javascript\n// This is short version of echo server\nwindow.rdd.TcpServer.create(function(server){\n  server.on('accept', function(client){\n    client.on('data', function(chunk){\n      client.send(chunk);\n    });\n  });\n  server.listen('0.0.0.0', 3001);\n});\n```\n\n## Events\n\n\n* `listen` [TcpServer] - socket becomes accept clients\n* `accept` [TcpSocket, TcpServer] - new client accepted\n* `close` [TcpServer] - socket closed\n* `disconnect` [TcpServer] - stops listening and closes all child sockets\n* `error` [code, error, sender] - raised error\n\n## API\n\n### [static] create\n\n``` create(done) ```\n\nCreates new instance of socket and wrap it to TcpServer\n\n* `done` [function(info)] - Done callback\n\n### [static] sockets\n\n``` sockets(done) ```\n\nRetrieves the list of currently opened sockets owned by the application.\nSee: https://developer.chrome.com/apps/sockets_tcpServer#type-SocketInfo .\n\n* `done` [function(`List\u003cSocketInfo\u003e`)] - Done callback\n\n\n### [constructor] TcpServer\n\n``` TcpServer(socketId) ```\n\nCreate new instance of TcpServer based on socket descriptor\n\n* `socketId` [integer] - Socket descriptor\n\n### pause\n\n``` pause(paused, done) ```\n\nSet pause state\n\n* `paused` [boolean] - Enable pause or not\n* `done` [function(info)] - Done callback\n\n### listen\n\n``` listen(address, port, backlog, done, unpause) ```\n\nSetup socket in listen mode and start accepting clients.\nEmits 'listen' on success.\n\n* `address` [string] - Bind host name or ip\n* `port` [integer] - Bind port number\n* `backlog` [integer] (default = 1) - Clients queue size\n* `done` [function(TcpServer)] - Done callback\n* `unpause` [boolean](default = true) - Unpause socket\n\n### disconnect\n\n``` disconnect(done) ```\n\nStop listening and close all child sockets. Emits 'disconnect' event\n\n* `done` [function(TcpServer)] - Done callback\n\n### close\n\n``` close(done) ```\n\nDestroy socket. Emits 'close'.\n\n* `done` [function(TcpServer)] - Done callback\n\n### info\n\n``` info(done) ```\n\nGet socket info.\nSee: https://developer.chrome.com/apps/sockets_tcpServer#type-SocketInfo\n\n* `done` [function(TcpServer)] - Done callback\n\n----\n\n\n# UdpSocket\n\nJavaScript: ` window.rdd.UdpSocket `\n\n[Original API](https://developer.chrome.com/apps/sockets_udp)\n\n\n## Example\n\nCoffeeScript:\n\n```coffeescript\nUdpSocket.create (sock)=\u003e\n    sock.on 'error', (code, err, from)-\u003e\n      console.log 'Error', code, from, err\n    sock.on 'data', (chunk, addr, port)-\u003e\n      console.log 'Data', ab2str8(chunk), 'from', addr, port\n\n    sock.bind '0.0.0.0', 0, ()=\u003e\n      console.log 'Bound'\n      sock.info (info)=\u003e\n        console.log 'Info', info\n        sock.send 'Hello world!', '127.0.0.1', info.localPort\n```\n\nJavaScript:\n\n```javascript\nwindow.rdd.UdpSocket.create(function(sock) {\n  sock.on('error', function(code, err, from) {\n    console.log('Error', code, from, err);\n  });\n  sock.on('data', function(chunk, addr, port) {\n    console.log('Data', ab2str8(chunk), 'from', addr, port);\n  });\n  sock.bind('0.0.0.0', 0, function() {\n    console.log('Bound');\n    sock.info(function(info) {\n      console.log('Info', info);\n      sock.send('Hello world!', '127.0.0.1', info.localPort);\n    });\n  });\n});\n```\n\n## Events\n\n\n* `bind` [address, port] - socket bound to address:port\n* `close` [UdpSocket] - socket closed\n* `join` [address, UdpSocket] - socket joined to multicast group\n* `leave` [address, UdpSocket] - socket leaved multicast group\n* `error` [code, error, sender] - raised error\n\n## API\n\n### [static] create\n\n``` create(done) ```\n\nCreates new instance of socket and wrap it to UdpSocket\n\n* `done` [function(UdpSocket)] - Done callback\n\n### [static] sockets\n\n``` sockets(done) ```\n\nRetrieves the list of currently opened sockets owned by the application.\nSee: https://developer.chrome.com/apps/sockets_udp#method-getSockets\n\n* `done` [function(`List\u003cSocketInfo\u003e`)] - Done callback\n\n### [constructor] UdpSocket\n\n``` UdpSocket(socketId) ```\n\nCreate new instance of UdpSocket\n\n* `socketId` [integer] - Socket descriptor\n\n### update\n\n``` update(properties, done) ```\n\nUpdates the socket properties.\nSee: https://developer.chrome.com/apps/sockets_udp#method-update\n\n* `properties` [SocketProperties] - The properties to update.\n* `done` [function(UdpSocket)] - Done callback\n\n### pause\n\n``` pause(state, done) ```\n\nPauses or unpauses a socket. A paused socket is not recieving data\n\n* `state` [boolean] - Pause or not\n* `done` [function(UdpSocket)] - Done callback\n\n### bind\n\n``` bind(address, port, done, unpause) ```\n\nBinds the local address and port for the socket.\nFor a client socket, it is recommended to use port 0 to let\nthe platform pick a free port.\n\n* `address` [string] - IP or address of machine\n* `port` [integer] - port number\n* `done` [function(UdpSocket)] - Done callback\n* `unpause` [boolean] (default = true) - Automatic unpause socket\n\n### send\n\n``` send(data, address, port, done) ```\n\nSends data on the given socket to the given address and port.\nThe socket must be bound to a local port before calling this method.\n\n* `data` [ArrayBuffer | String] - Message to send\n* `address` [string] - IP or address of target machine\n* `port` [integer] - port number\n* `done` [function(UdpSocket)] - Done callback\n\n### close\n\n``` close(done) ```\n\nCloses the socket and releases the address/port the socket is bound to.\n\n* `done` [function(UdpSocket)] - Done callback\n\n### info\n\n``` info(done) ```\n\nRetrieves the state of the given socket\n\n* `done` [function(SocketInfo, UdpSocket)] - Done callback\n\n### join\n\n``` join(address, done) ```\n\nJoins the multicast group and starts to receive packets from that group.\nThe socket must be bound to a local port before calling this method.\n\n* `address` [string] - multicast address\n* `done` [function(UdpSocket)] - Done callback\n\n### leave\n\n``` leave(address, done) ```\n\nLeaves the multicast group previously joined\n\n* `address` [string] - multicast address\n* `done` [function(UdpSocket)] - Done callback\n\n### multicastTTL\n\n``` multicastTTL(ttl, done) ```\n\nSets the time-to-live of multicast packets sent to the multicast group.\n\n* `ttl` [integer] - The time-to-live value\n* `done` [function(UdpSocket)] - Done callback\n\n### multicastLoopback\n\n``` multicastLoopback(enable, done) ```\n\nSets whether multicast packets sent from the host to the multicast group\nwill be looped back to the host.\n\n* `enable` [boolean] - Indicate whether to enable loopback mode.\n* `done` [function(UdpSocket)] - Done callback\n\n### joinedGroups\n\n``` joinedGroups(done) ```\n\nGets the multicast group addresses the socket is currently joined to.\n\n* done [function(UdpSocket)] - Done callback\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fchrome","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freddec%2Fchrome","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fchrome/lists"}