npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mikudos-socketio-app

v1.0.0

Published

mikudos-socketio-app for connection and call methods and sync events on mikudos-socketio-app server, which is provided only for socket.io connection.

Downloads

42

Readme

Mikudos Gate

Mikudos

MIKUDOS SOCKETIO GATE

mikudos-socketio-gate.

node version version npm version license downloads collaborators typescript

mikudos

Example

A Example implementation of mikudos-socketio-app in typescript can be found as the linked repository.

Usage

npm install mikudos-socketio-app --save

Import the mikudos-socketio-app module:

import {
  Application,
  Authentication,
  AuthenticationRequest,
  RpcServiceMethods,
  JSON_RPC_HANDLER,
  CHAT_HANDLER,
  DUPLEX_HANDLER,
} from 'mikudos-socketio-app';

import http from 'http';
import socket from 'socket.io';
import rpcs from './rpcs';
import publish from './publish';
import authentication from './authentication';
import message from './message';
import duplexs from './duplexs';
import inter_service_clients from './inter_service_clients';

const server = http.createServer();
const io = socket(server);

const app = new Application(io);
app.configure(inter_service_clients);
app.configure(authentication);
app.configure(rpcs);
app.configure(publish);
app.configure(message);
app.configure(duplexs);

app.init();

server.listen(app.get('port'));
console.log('socket.io server started at port: ' + app.get('port'));
var {
  Application,
  Authentication,
  AuthenticationRequest,
  RpcServiceMethods,
  JSON_RPC_HANDLER,
  CHAT_HANDLER,
  DUPLEX_HANDLER,
} = require('mikudos-socketio-app');

implement duplex services

import { Application, DUPLEX_HANDLER } from 'mikudos-socketio-app';
import { StreamService } from './stream_service';

// register duplext service on the application
export = function (app: Application): void {
  app.duplex_services = new DUPLEX_HANDLER(app, [StreamService]);
};
// file:: stream_service
import { EventEmitter } from 'events';
import { Application, DUPLEX_HANDLER, mikudos } from 'mikudos-socketio-app';
const JsonRpcError = require('json-rpc-error');
const grpc_caller = require('grpc-caller');
import path from 'path';

const LOAD = {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
};
const key = 'stream_service';
const serverIp = '127.0.0.1';
const port = '40051';

export class StreamService implements mikudos.DuplexService {
  static serviceKey = key;
  public before = {
    all: [
      (methodPath: string, data: any, socket: mikudos.Socket) => {
        if (!socket?.mikudos?.user) {
          throw new JsonRpcError('Not Authenticated', -32088, {
            info: '未认证的请求',
          });
        }
        return data;
      },
    ],
    method1: [
      (methodPath: string, data: any, socket: mikudos.Socket) => {
        // stransport data can be modified before service method
        return data;
      },
    ],
  };
  private protoFile = path.resolve(
    __dirname,
    '../../proto/stream/stream.proto',
  );
  private serviceCaller: any;
  constructor(private handler: DUPLEX_HANDLER, private app: Application) {
    this.serviceCaller = grpc_caller(
      `${serverIp}:${port}`,
      { file: this.protoFile, load: LOAD },
      'StreamService',
    );
  }

  /**
   *
   * @param pathStr 请求方法路径: [空间].[方法名]
   * @param data 请求参数
   * @param event socketIo同步客户端触发事件
   */
  async SyncSceneInstance(
    eventName: string,
    data: any,
    socketEvent: EventEmitter,
  ) {}
}

example stream.proto file

syntax = "proto3";
// import "proto/include/google/protobuf/any.proto";
package stream;

service StreamService {
  rpc SyncSceneInstance(stream ClientGameEventMessage)
      returns (stream ServerGameEventMessage) {}
}

new update

Add redisAdapter for horizontal spread

The Architecture show the way to cross centralization with help of grpc duplex communication and socketio with Event manager.

Migrate from 0.2.3 to 0.3.x
// 0.2.3
import { Application, DUPLEX_HANDLER } from 'mikudos-socketio-app';
import { key, RealTime } from './real_time_game';

export = function (app: Application): void {
  app.duplex_services = new DUPLEX_HANDLER(app, [{ key, sc: RealTime }]);
};

// 0.3.x
import { Application, DUPLEX_HANDLER } from 'mikudos-socketio-app';
import { key, RealTime } from './real_time_game';

export = function (app: Application): void {
  app.duplex_services = new DUPLEX_HANDLER(app, [RealTime]);
};

License

MIT