Parcel extension addded
This commit is contained in:
parent
73c164b65e
commit
0e1bcc0f6c
|
@ -2,7 +2,7 @@ interface IConnection{
|
|||
endpoint: string;
|
||||
autoPair?: boolean;
|
||||
}
|
||||
export default class Connection
|
||||
export class Connection
|
||||
{
|
||||
public ws! : WebSocket;
|
||||
public endpoint : URL;
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
import {Connection} from "./Connection";
|
||||
export default class WSTS {
|
||||
public connection? : Connection;
|
||||
public a = 25;
|
||||
constructor(){
|
||||
this.connection = new Connection({
|
||||
endpoint: "25"
|
||||
});
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
|
@ -2,9 +2,18 @@
|
|||
"name": "mwse",
|
||||
"version": "0.1.0",
|
||||
"description": "Mikro WebSocket Engine",
|
||||
"main": "Source/index.js",
|
||||
"scripts": {
|
||||
"compile": "tsc -p tsconfig.json -w"
|
||||
"compile": "parcel watch --no-hmr"
|
||||
},
|
||||
"source": "./frontend/index.ts",
|
||||
"targets":{
|
||||
"default":{
|
||||
"distDir" : "./script/",
|
||||
"publicUrl": "./",
|
||||
"sourceMap": true,
|
||||
"outputFormat": "global",
|
||||
"optimize": true
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -28,5 +37,9 @@
|
|||
"terminal-kit": "^3.0.0",
|
||||
"typescript": "^4.9.3",
|
||||
"websocket": "^1.0.34"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@parcel/packager-ts": "^2.7.0",
|
||||
"@parcel/transformer-typescript-types": "^2.7.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
interface IConnection {
|
||||
endpoint: string;
|
||||
autoPair?: boolean;
|
||||
}
|
||||
export default class Connection {
|
||||
ws: WebSocket;
|
||||
endpoint: URL;
|
||||
autoPair: boolean;
|
||||
connected: boolean;
|
||||
constructor(options: IConnection);
|
||||
connect(): void;
|
||||
addWSEvents(): void;
|
||||
private eventOpen;
|
||||
private eventClose;
|
||||
private eventError;
|
||||
private recaivePackEvent;
|
||||
onRecaivePack(func: (data: any) => any): void;
|
||||
private eventMessage;
|
||||
tranferToServer(data: any): void;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=Connection.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"Connection.d.ts","sourceRoot":"","sources":["../frontend/Connection.ts"],"names":[],"mappings":"AAAA,UAAU,WAAW;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AACD,MAAM,CAAC,OAAO,OAAO,UAAU;IAEpB,EAAE,EAAI,SAAS,CAAC;IAChB,QAAQ,EAAG,GAAG,CAAC;IACf,QAAQ,EAAG,OAAO,CAAS;IAC3B,SAAS,EAAG,OAAO,CAAS;gBACvB,OAAO,EAAE,WAAW;IAKzB,OAAO;IAKP,WAAW;IAOlB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,gBAAgB,CAA8B;IAC/C,aAAa,CAAC,IAAI,EAAC,CAAC,IAAI,EAAC,GAAG,KAAK,GAAG;IAI3C,OAAO,CAAC,YAAY;IASb,eAAe,CAAC,IAAI,EAAC,GAAG;CAOlC"}
|
|
@ -1,52 +0,0 @@
|
|||
var Connection = (function () {
|
||||
function Connection(options) {
|
||||
this.autoPair = false;
|
||||
this.connected = false;
|
||||
this.recaivePackEvent = [];
|
||||
this.endpoint = new URL(options.endpoint);
|
||||
this.autoPair = options.autoPair || false;
|
||||
this.connect();
|
||||
}
|
||||
Connection.prototype.connect = function () {
|
||||
this.ws = new WebSocket(this.endpoint.href);
|
||||
this.addWSEvents();
|
||||
};
|
||||
Connection.prototype.addWSEvents = function () {
|
||||
var _this = this;
|
||||
this.ws.addEventListener("open", function () { return _this.eventOpen(); });
|
||||
this.ws.addEventListener("close", function () { return _this.eventClose(); });
|
||||
this.ws.addEventListener("error", function () { return _this.eventError(); });
|
||||
this.ws.addEventListener("message", function (_a) {
|
||||
var data = _a.data;
|
||||
return _this.eventMessage(data);
|
||||
});
|
||||
};
|
||||
Connection.prototype.eventOpen = function () {
|
||||
this.connected = true;
|
||||
};
|
||||
Connection.prototype.eventClose = function () {
|
||||
this.connected = false;
|
||||
};
|
||||
Connection.prototype.eventError = function () {
|
||||
this.connected = false;
|
||||
};
|
||||
Connection.prototype.onRecaivePack = function (func) {
|
||||
this.recaivePackEvent.push(func);
|
||||
};
|
||||
Connection.prototype.eventMessage = function (data) {
|
||||
if (typeof data == "string") {
|
||||
for (var _i = 0, _a = this.recaivePackEvent; _i < _a.length; _i++) {
|
||||
var callback = _a[_i];
|
||||
callback(JSON.parse(data));
|
||||
}
|
||||
}
|
||||
};
|
||||
Connection.prototype.tranferToServer = function (data) {
|
||||
if (this.connected) {
|
||||
this.ws.send(JSON.stringify(data));
|
||||
}
|
||||
};
|
||||
return Connection;
|
||||
}());
|
||||
export default Connection;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29ubmVjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL2Zyb250ZW5kL0Nvbm5lY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUE7SUFNSSxvQkFBWSxPQUFvQjtRQUZ6QixhQUFRLEdBQWEsS0FBSyxDQUFDO1FBQzNCLGNBQVMsR0FBYSxLQUFLLENBQUM7UUE4QjNCLHFCQUFnQixHQUEyQixFQUFFLENBQUM7UUE1QmxELElBQUksQ0FBQyxRQUFRLEdBQUcsSUFBSSxHQUFHLENBQUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDO1FBQzFDLElBQUksQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFDLFFBQVEsSUFBSSxLQUFLLENBQUM7UUFDMUMsSUFBSSxDQUFDLE9BQU8sRUFBR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JcbiAgICB7XHJcbiAgICAgICAgdGhpcy5jb25uZWN0ZWQgPSBmYWxzZTtcclxuICAgIH1cclxuICAgIHByaXZhdGUgZXZlbnRFcnJvcigpXHJcbiAgICB7XHJcbiAgICAgICAgdGhpcy5jb25uZWN0ZWQgPSBmYWxzZTtcclxuICAgIH1cclxuICAgIHByaXZhdGUgcmVjYWl2ZVBhY2tFdmVudCA6ICgoZGF0YTphbnkpID0+IGFueSlbXSA9IFtdO1xyXG4gICAgcHVibGljIG9uUmVjYWl2ZVBhY2soZnVuYzooZGF0YTphbnkpID0+IGFueSlcclxuICAgIHtcclxuICAgICAgICB0aGlzLnJlY2FpdmVQYWNrRXZlbnQucHVzaChmdW5jKTtcclxuICAgIH1cclxuICAgIHByaXZhdGUgZXZlbnRNZXNzYWdlKGRhdGE6IHN0cmluZyB8IEFycmF5QnVmZmVyKVxyXG4gICAge1xyXG4gICAgICAgIGlmKHR5cGVvZiBkYXRhID09IFwic3RyaW5nXCIpXHJcbiAgICAgICAge1xyXG4gICAgICAgICAgICBmb3IgKGNvbnN0IGNhbGxiYWNrIG9mIHRoaXMucmVjYWl2ZVBhY2tFdmVudCkge1xyXG4gICAgICAgICAgICAgICAgY2FsbGJhY2soSlNPTi5wYXJzZShkYXRhKSk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICB9XHJcbiAgICBwdWJsaWMgdHJhbmZlclRvU2VydmVyKGRhdGE6YW55KVxyXG4gICAge1xyXG4gICAgICAgIGlmKHRoaXMuY29ubmVjdGVkKVxyXG4gICAgICAgIHtcclxuICAgICAgICAgICAgdGhpcy53cy5zZW5kKEpTT04uc3RyaW5naWZ5KGRhdGEpKTtcclxuICAgICAgICB9XHJcbiAgICB9XHJcbn0iXX0=
|
|
@ -1,4 +0,0 @@
|
|||
export default class WSTS {
|
||||
connection?: Connection;
|
||||
}
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../frontend/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,IAAI;IACd,UAAU,CAAC,EAAG,UAAU,CAAC;CACnC"}
|
239
script/index.js
239
script/index.js
|
@ -1,7 +1,234 @@
|
|||
var WSTS = (function () {
|
||||
function WSTS() {
|
||||
// modules are defined as an array
|
||||
// [ module function, map of requires ]
|
||||
//
|
||||
// map of requires is short require name -> numeric require
|
||||
//
|
||||
// anything defined in a previous bundle is accessed via the
|
||||
// orig method which is the require for previous bundles
|
||||
|
||||
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
||||
/* eslint-disable no-undef */
|
||||
var globalObject =
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof global !== 'undefined'
|
||||
? global
|
||||
: {};
|
||||
/* eslint-enable no-undef */
|
||||
|
||||
// Save the require from previous bundle to this closure if any
|
||||
var previousRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
|
||||
var cache = previousRequire.cache || {};
|
||||
// Do not use `require` to prevent Webpack from trying to bundle this call
|
||||
var nodeRequire =
|
||||
typeof module !== 'undefined' &&
|
||||
typeof module.require === 'function' &&
|
||||
module.require.bind(module);
|
||||
|
||||
function newRequire(name, jumped) {
|
||||
if (!cache[name]) {
|
||||
if (!modules[name]) {
|
||||
// if we cannot find the module within our internal map or
|
||||
// cache jump to the current global require ie. the last bundle
|
||||
// that was added to the page.
|
||||
var currentRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
if (!jumped && currentRequire) {
|
||||
return currentRequire(name, true);
|
||||
}
|
||||
|
||||
// If there are other bundles on this page the require from the
|
||||
// previous one is saved to 'previousRequire'. Repeat this as
|
||||
// many times as there are bundles until the module is found or
|
||||
// we exhaust the require chain.
|
||||
if (previousRequire) {
|
||||
return previousRequire(name, true);
|
||||
}
|
||||
|
||||
// Try the node require function if it exists.
|
||||
if (nodeRequire && typeof name === 'string') {
|
||||
return nodeRequire(name);
|
||||
}
|
||||
|
||||
var err = new Error("Cannot find module '" + name + "'");
|
||||
err.code = 'MODULE_NOT_FOUND';
|
||||
throw err;
|
||||
}
|
||||
|
||||
localRequire.resolve = resolve;
|
||||
localRequire.cache = {};
|
||||
|
||||
var module = (cache[name] = new newRequire.Module(name));
|
||||
|
||||
modules[name][0].call(
|
||||
module.exports,
|
||||
localRequire,
|
||||
module,
|
||||
module.exports,
|
||||
this
|
||||
);
|
||||
}
|
||||
return WSTS;
|
||||
}());
|
||||
export default WSTS;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9mcm9udGVuZC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtJQUFBO0lBRUEsQ0FBQztJQUFELFdBQUM7QUFBRCxDQUFDLEFBRkQsSUFFQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IGNsYXNzIFdTVFMge1xyXG4gICAgcHVibGljIGNvbm5lY3Rpb24/IDogQ29ubmVjdGlvbjtcclxufSJdfQ==
|
||||
|
||||
return cache[name].exports;
|
||||
|
||||
function localRequire(x) {
|
||||
var res = localRequire.resolve(x);
|
||||
return res === false ? {} : newRequire(res);
|
||||
}
|
||||
|
||||
function resolve(x) {
|
||||
var id = modules[name][1][x];
|
||||
return id != null ? id : x;
|
||||
}
|
||||
}
|
||||
|
||||
function Module(moduleName) {
|
||||
this.id = moduleName;
|
||||
this.bundle = newRequire;
|
||||
this.exports = {};
|
||||
}
|
||||
|
||||
newRequire.isParcelRequire = true;
|
||||
newRequire.Module = Module;
|
||||
newRequire.modules = modules;
|
||||
newRequire.cache = cache;
|
||||
newRequire.parent = previousRequire;
|
||||
newRequire.register = function (id, exports) {
|
||||
modules[id] = [
|
||||
function (require, module) {
|
||||
module.exports = exports;
|
||||
},
|
||||
{},
|
||||
];
|
||||
};
|
||||
|
||||
Object.defineProperty(newRequire, 'root', {
|
||||
get: function () {
|
||||
return globalObject[parcelRequireName];
|
||||
},
|
||||
});
|
||||
|
||||
globalObject[parcelRequireName] = newRequire;
|
||||
|
||||
for (var i = 0; i < entry.length; i++) {
|
||||
newRequire(entry[i]);
|
||||
}
|
||||
|
||||
if (mainEntry) {
|
||||
// Expose entry point to Node, AMD or browser globals
|
||||
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
|
||||
var mainExports = newRequire(mainEntry);
|
||||
|
||||
// CommonJS
|
||||
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
||||
module.exports = mainExports;
|
||||
|
||||
// RequireJS
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
define(function () {
|
||||
return mainExports;
|
||||
});
|
||||
|
||||
// <script>
|
||||
} else if (globalName) {
|
||||
this[globalName] = mainExports;
|
||||
}
|
||||
}
|
||||
})({"jQXDy":[function(require,module,exports) {
|
||||
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
||||
parcelHelpers.defineInteropFlag(exports);
|
||||
var _connection = require("./Connection");
|
||||
class WSTS {
|
||||
a = 25;
|
||||
constructor(){
|
||||
this.connection = new (0, _connection.Connection)({
|
||||
endpoint: "25"
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.default = WSTS;
|
||||
|
||||
},{"./Connection":"aAICD","@parcel/transformer-js/src/esmodule-helpers.js":"e7rGL"}],"aAICD":[function(require,module,exports) {
|
||||
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
||||
parcelHelpers.defineInteropFlag(exports);
|
||||
parcelHelpers.export(exports, "Connection", ()=>Connection);
|
||||
class Connection {
|
||||
autoPair = false;
|
||||
connected = false;
|
||||
constructor(options){
|
||||
this.endpoint = new URL(options.endpoint);
|
||||
this.autoPair = options.autoPair || false;
|
||||
this.connect();
|
||||
}
|
||||
connect() {
|
||||
this.ws = new WebSocket(this.endpoint.href);
|
||||
this.addWSEvents();
|
||||
}
|
||||
addWSEvents() {
|
||||
this.ws.addEventListener("open", ()=>this.eventOpen());
|
||||
this.ws.addEventListener("close", ()=>this.eventClose());
|
||||
this.ws.addEventListener("error", ()=>this.eventError());
|
||||
this.ws.addEventListener("message", ({ data })=>this.eventMessage(data));
|
||||
}
|
||||
eventOpen() {
|
||||
this.connected = true;
|
||||
}
|
||||
eventClose() {
|
||||
this.connected = false;
|
||||
}
|
||||
eventError() {
|
||||
this.connected = false;
|
||||
}
|
||||
recaivePackEvent = [];
|
||||
onRecaivePack(func) {
|
||||
this.recaivePackEvent.push(func);
|
||||
}
|
||||
eventMessage(data) {
|
||||
if (typeof data == "string") for (const callback of this.recaivePackEvent)callback(JSON.parse(data));
|
||||
}
|
||||
tranferToServer(data) {
|
||||
if (this.connected) this.ws.send(JSON.stringify(data));
|
||||
}
|
||||
}
|
||||
|
||||
},{"@parcel/transformer-js/src/esmodule-helpers.js":"e7rGL"}],"e7rGL":[function(require,module,exports) {
|
||||
exports.interopDefault = function(a) {
|
||||
return a && a.__esModule ? a : {
|
||||
default: a
|
||||
};
|
||||
};
|
||||
exports.defineInteropFlag = function(a) {
|
||||
Object.defineProperty(a, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
};
|
||||
exports.exportAll = function(source, dest) {
|
||||
Object.keys(source).forEach(function(key) {
|
||||
if (key === "default" || key === "__esModule" || dest.hasOwnProperty(key)) return;
|
||||
Object.defineProperty(dest, key, {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return source[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
return dest;
|
||||
};
|
||||
exports.export = function(dest, destName, get) {
|
||||
Object.defineProperty(dest, destName, {
|
||||
enumerable: true,
|
||||
get: get
|
||||
});
|
||||
};
|
||||
|
||||
},{}]},["jQXDy"], "jQXDy", "parcelRequiref9d4")
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue