airfone-client-js
Advanced tools
Comparing version 0.0.12 to 0.0.13
export declare type StatusEvent = 'connect' | 'disconnect' | 'online' | 'offline' | 'error'; | ||
export declare type MessageEvent = 'group' | 'role' | 'message'; | ||
export declare type MessageEvent = 'group' | 'role' | 'message' | 'broadcasts'; | ||
export declare class ClientOptions { | ||
@@ -9,3 +9,5 @@ readonly server?: String; | ||
readonly token?: String; | ||
constructor(id: String, role: String, room: String, server?: String, token?: String); | ||
readonly source?: String; | ||
constructor(id: String, role: String, room: String, server?: String, token?: String, source?: String); | ||
static build({ id, role, room, server, token, source }: any): ClientOptions; | ||
} | ||
@@ -33,2 +35,3 @@ /** | ||
broadcast(payload: any): void; | ||
broadcasts(payload: any): void; | ||
on(events: StatusEvent | MessageEvent | String | Array<StatusEvent | MessageEvent | String>, handle?: (payload: Payload) => void): AirfoneClient; | ||
@@ -35,0 +38,0 @@ } |
@@ -9,6 +9,7 @@ import { io } from 'socket.io-client'; | ||
EventType.BROADCAST = "broadcast"; // 通知群里面所有人员 | ||
EventType.BROADCASTS = "broadcasts"; // 通知同源所有人员 | ||
const ReceiveFunctionMap = new Map(); | ||
const path = 'airline/dispatch'; | ||
export class ClientOptions { | ||
constructor(id, role, room, server, token) { | ||
constructor(id, role, room, server, token, source) { | ||
this.id = id; | ||
@@ -19,3 +20,7 @@ this.role = role; | ||
this.token = token; | ||
this.source = source; | ||
} | ||
static build({ id, role, room, server, token, source }) { | ||
return new ClientOptions(id, role, room, server, token, source); | ||
} | ||
} | ||
@@ -66,2 +71,6 @@ export default class AirfoneClient { | ||
}); | ||
this.options.source && this.socket.on(`broadcasts/${this.options.source}`, (data) => { | ||
var _a; | ||
(_a = this.events.get('broadcasts')) === null || _a === void 0 ? void 0 : _a.call(this, data); | ||
}); | ||
this.listeners.forEach((handle, event) => { | ||
@@ -123,2 +132,17 @@ this.socket.on(`${room}/${event}`, (payload) => { | ||
} | ||
broadcasts(payload) { | ||
let { state, options: { source } } = this; | ||
if (state !== 2) { | ||
throw new Error('连接未建立,无法发送消息'); | ||
} | ||
else if (!source) { | ||
throw new Error('Source NotFound'); | ||
} | ||
this.socket.send({ | ||
source: this.options.source, | ||
endpoint: path, | ||
event: EventType.BROADCASTS, | ||
payload | ||
}); | ||
} | ||
on(events, handle = (payload) => { }) { | ||
@@ -133,2 +157,5 @@ if (this.state != 0) { | ||
array.forEach(event => { | ||
if (event === 'broadcast' && !this.options.source) { | ||
throw new Error('broadcast监听需要source属性支持'); | ||
} | ||
try { | ||
@@ -135,0 +162,0 @@ // @ts-ignore |
{ | ||
"name": "airfone-client-js", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8757
207