Browse Source

Add Node.js support

tags/v0.3.0
Garrett Mills 4 months ago
parent
commit
fc48c16576
4 changed files with 176 additions and 1 deletions
  1. 90
    0
      .gitignore
  2. 21
    1
      flitter-socket.js
  3. 13
    0
      package.json
  4. 52
    0
      yarn.lock

+ 90
- 0
.gitignore View File

@@ -0,0 +1,90 @@

# Created by https://www.gitignore.io/api/node
# Edit at https://www.gitignore.io/?templates=node

.idea
.idea/*

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# End of https://www.gitignore.io/api/node

+ 21
- 1
flitter-socket.js View File

@@ -1,3 +1,12 @@
let _FWS
let uuid
if ( typeof process === 'object' && typeof window === 'undefined' ) {
// We're in Node.js!
_FWS = require('websocket').w3cwebsocket
uuid = require('uuid/v4')
}
else _FWS = WebSocket

class FlitterSocketTransaction {
constructor(data, conn) {
this.type = data.type
@@ -123,7 +132,7 @@ class FlitterSocketConnection {
}

_create_socket() {
this.socket = new WebSocket(this.url)
this.socket = new _FWS(this.url)
this.socket.onopen = (e) => this.open = true
this.socket.onmessage = this._on_message.bind(this)
this.socket.onclose = (e) => {
@@ -227,6 +236,7 @@ class FlitterSocketConnection {
}

uuid() {
if (typeof uuid === 'function') return uuid()
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
@@ -247,3 +257,13 @@ class FlitterSocketConnection {
}
}
}

if ( typeof process === 'object' && typeof window === 'undefined' ) {
// We're in Node.js
module.exports = exports = {
connection: FlitterSocketConnection,
client_server: FlitterSocketClientServerTransaction,
server_client: FlitterSocketServerClientTransaction,
transaction: FlitterSocketTransaction
}
}

+ 13
- 0
package.json View File

@@ -0,0 +1,13 @@
{
"name": "flitter-socket-client-js",
"version": "0.1.0",
"description": "A flitter-socket client implementation for Node.js",
"main": "flitter-socket.js",
"repository": "https://git.garrettmills.dev/flitter/socket-client-js",
"author": "garrettmills <garrett@garrettmills.dev>",
"license": "MIT",
"dependencies": {
"uuid": "^3.3.3",
"websocket": "^1.0.30"
}
}

+ 52
- 0
yarn.lock View File

@@ -0,0 +1,52 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


debug@^2.2.0:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
dependencies:
ms "2.0.0"

is-typedarray@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=

ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=

nan@^2.14.0:
version "2.14.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==

typedarray-to-buffer@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"
integrity sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==
dependencies:
is-typedarray "^1.0.0"

uuid@^3.3.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.3.tgz#4568f0216e78760ee1dbf3a4d2cf53e224112866"
integrity sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==

websocket@^1.0.30:
version "1.0.30"
resolved "https://registry.yarnpkg.com/websocket/-/websocket-1.0.30.tgz#91d3bd00c3d43e916f0cf962f8f8c451bb0b2373"
integrity sha512-aO6klgaTdSMkhfl5VVJzD5fm+Srhh5jLYbS15+OiI1sN6h/RU/XW6WN9J1uVIpUKNmsTvT3Hs35XAFjn9NMfOw==
dependencies:
debug "^2.2.0"
nan "^2.14.0"
typedarray-to-buffer "^3.1.5"
yaeti "^0.0.6"

yaeti@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/yaeti/-/yaeti-0.0.6.tgz#f26f484d72684cf42bedfb76970aa1608fbf9577"
integrity sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc=

Loading…
Cancel
Save