# pomelo-creator

> ##Install

Latest version **1.3.7** (published 2018-11-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install pomelo-creator
pnpm add pomelo-creator
yarn add pomelo-creator
bun add pomelo-creator
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.7 |
| Published | 2018-11-29 |
| First published | 2018-09-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 52.1 KB |
| Known vulnerabilities | 0 (+11 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Maintainers | dmedivh |

## Links

- npm: https://www.npmjs.com/package/pomelo-creator
- Repository: https://github.com/DMedivh/pomelo-creator-ts
- Homepage: https://github.com/DMedivh/pomelo-creator-ts#readme
- Issues: https://github.com/DMedivh/pomelo-creator-ts/issues
- npm.io page: https://npm.io/package/pomelo-creator

## Dependencies (6)

- [is](https://npm.io/package/is.md) ^3.2.1
- [url](https://npm.io/package/url.md) ^0.11.0
- [util](https://npm.io/package/util.md) ^0.11.0
- [moment](https://npm.io/package/moment.md) ^2.22.2
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.8.8
- [eventemitter3](https://npm.io/package/eventemitter3.md) ^3.1.0

## Recent versions

- 1.3.7 (latest) — 2018-11-29
- 1.3.6 — 2018-11-29
- 1.3.5 — 2018-11-28
- 1.3.4 — 2018-11-28
- 1.3.3 — 2018-11-28
- 1.3.2 — 2018-11-28
- 1.3.1 — 2018-11-28
- 1.3.0 — 2018-11-28
- 1.2.0 — 2018-09-26
- 1.1.3 — 2018-09-26
- 1.1.2 — 2018-09-21
- 1.1.1 — 2018-09-18
- 1.1.0 — 2018-09-17
- 1.0.5 — 2018-09-17
- 1.0.4 — 2018-09-17
- … 4 more at https://npm.io/package/pomelo-creator/versions

## README

#pomelo 游戏框架的 creator 连接代码

##Install

        npm install pomelo-creator --save

##Usage

        import { pomelo } from "pomelo-creator";

        pomelo.create('ws://127.0.0.1:3010',{

            /// 注意 auth 函数是一个 promise 方法
            auth:async(){
                /// 这是一个自动对连接鉴权的函数,
                /// 例如: 
                /// connection 内部封装了一个 getItem setIiem 的方法用来获取本地存储
                const sessionId = pomelo.connection.getItem("sessionId");
                if( sessionId ){
                    /// 这里的路由方法需要在服务器实现(相当于一个断线重连恢复玩家服务器数据的功能)
                    const ok = await pomelo.connection.request("connector.session.auth",{ sessionId });
                    if( !ok ){
                        pomelo.connection.setItem('sessionId',undefined);
                    }
                }
            }
        }).then((session)=>{
            console.log("连接完成");
        });

        pomelo.connection.on('error',()=>{
            /// 这是socket 错误的事件
        });
        pomelo.connection.on('connected',()=>{
            /// 这是链接初始化完成的事件(注意区别于鉴权 ready )
        });
        pomelo.connecion.on('disconnected',()=>{
            /// 这是 socket 断开连接的事件
        });
        pomelo.connection.on('reconnect',()=>{
            /// 这是自动重连的事件
        });
        pomelo.connection.on('ready',()=>{
            /// 这是鉴权完成后的事件
        });

---
_Source: https://npm.io/package/pomelo-creator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
