Skip to content

Commit a9377eb

Browse files
committed
static fixes
1 parent 697a564 commit a9377eb

File tree

6 files changed

+57
-157
lines changed

6 files changed

+57
-157
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
"name": "George Boot"
1919
},
2020
"license": "MIT",
21-
"main": "dist/laravel-echo-api-gateway-connector.common.js",
22-
"module": "dist/laravel-echo-api-gateway-connector.js",
23-
"types": "dist/laravel-echo-api-gateway-connector.d.ts",
21+
"main": "dist/laravel-echo-api-gateway.common.js",
22+
"module": "dist/laravel-echo-api-gateway.js",
23+
"types": "dist/laravel-echo-api-gateway.d.ts",
2424
"scripts": {
2525
"build": "npm run compile && npm run declarations",
2626
"compile": "./node_modules/.bin/rollup -c",
2727
"declarations": "./node_modules/.bin/tsc --emitDeclarationOnly",
28-
"lint": "eslint --ext .js,.ts ./src ./tests",
28+
"lint": "eslint --ext .js,.ts ./src",
2929
"prepublish": "npm run build",
3030
"release": "npm run test && standard-version && git push --follow-tags && npm publish",
3131
"test": "jest"

rollup.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import babel from '@rollup/plugin-babel';
22
import typescript from 'rollup-plugin-typescript2';
33

44
export default {
5-
input: './src/LaravelEchoApiGatewayConnector.ts',
5+
input: './src/Connector.ts',
66
output: [
7-
{ file: './dist/laravel-echo-api-gateway-connector.js', format: 'esm' },
8-
{ file: './dist/laravel-echo-api-gateway-connector.common.js', format: 'cjs' },
9-
{ file: './dist/laravel-echo-api-gateway-connector.iife.js', format: 'iife', name: 'LaravelEchoApiGatewayConnector' },
7+
{ file: './dist/laravel-echo-api-gateway.js', format: 'esm' },
8+
{ file: './dist/laravel-echo-api-gateway.common.js', format: 'cjs' },
9+
{ file: './dist/laravel-echo-api-gateway.iife.js', format: 'iife', name: 'LaravelEchoApiGateway' },
1010
],
1111
plugins: [
1212
typescript(),

src/ApiGatewayChannel.ts renamed to src/Channel.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import {EventFormatter} from 'laravel-echo/src/util';
2-
import {Channel} from 'laravel-echo/src/channel/channel';
2+
import {Channel as BaseChannel} from 'laravel-echo/src/channel/channel';
33
import {PresenceChannel} from "laravel-echo/src/channel";
4-
import {LaravelEchoApiGatewayWebsocket} from "./LaravelEchoApiGatewayWebsocket";
4+
import {Websocket} from "./Websocket";
55

66
/**
77
* This class represents a Pusher channel.
88
*/
9-
export class ApiGatewayChannel extends Channel implements PresenceChannel {
9+
export class Channel extends BaseChannel implements PresenceChannel {
1010
/**
1111
* The Pusher client instance.
1212
*/
13-
socket: LaravelEchoApiGatewayWebsocket;
13+
socket: Websocket;
1414

1515
/**
1616
* The name of the channel.
1717
*/
18-
name: any;
18+
name: string;
1919

2020
/**
2121
* Channel options.
2222
*/
23-
options: any;
23+
options: object;
2424

2525
/**
2626
* The event formatter.
@@ -32,13 +32,13 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
3232
/**
3333
* Create a new class instance.
3434
*/
35-
constructor(socket: LaravelEchoApiGatewayWebsocket, name: any, options: any) {
35+
constructor(socket: Websocket, name: string, options: object) {
3636
super();
3737

3838
this.name = name;
3939
this.socket = socket;
4040
this.options = options;
41-
this.eventFormatter = new EventFormatter(this.options.namespace);
41+
this.eventFormatter = new EventFormatter(this.options["namespace"]);
4242

4343
this.subscribe();
4444
}
@@ -54,13 +54,13 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
5454
* Unsubscribe from a Pusher channel.
5555
*/
5656
unsubscribe(): void {
57-
this.socket.unsubscribe(this.name);
57+
this.socket.unsubscribe(this);
5858
}
5959

6060
/**
6161
* Listen for an event on the channel instance.
6262
*/
63-
listen(event: string, callback: Function): ApiGatewayChannel {
63+
listen(event: string, callback: Function): Channel {
6464
this.on(this.eventFormatter.format(event), callback);
6565

6666
return this;
@@ -69,7 +69,7 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
6969
/**
7070
* Stop listening for an event on the channel instance.
7171
*/
72-
stopListening(event: string, callback?: Function): ApiGatewayChannel {
72+
stopListening(event: string, callback?: Function): Channel {
7373
if (this.listeners[event] && (!callback || this.listeners[event] === callback)) {
7474
delete this.listeners[event]
7575
}
@@ -80,7 +80,7 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
8080
/**
8181
* Register a callback to be called anytime a subscription succeeds.
8282
*/
83-
subscribed(callback: Function): ApiGatewayChannel {
83+
subscribed(callback: Function): Channel {
8484
this.on('subscription_succeeded', () => {
8585
callback();
8686
});
@@ -91,7 +91,7 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
9191
/**
9292
* Register a callback to be called anytime a subscription error occurs.
9393
*/
94-
error(callback: Function): ApiGatewayChannel {
94+
error(callback: Function): Channel {
9595
this.on('error', (status) => {
9696
callback(status);
9797
});
@@ -102,19 +102,19 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
102102
/**
103103
* Bind a channel to an event.
104104
*/
105-
on(event: string, callback: Function): ApiGatewayChannel {
105+
on(event: string, callback: Function): Channel {
106106
this.listeners[event] = callback
107107

108108
return this;
109109
}
110110

111-
handleEvent(event: string, data: object) {
111+
handleEvent(event: string, data: object): void {
112112
if (this.listeners[event]) {
113113
this.listeners[event](event, data)
114114
}
115115
}
116116

117-
whisper(event: string, data: object): ApiGatewayChannel {
117+
whisper(event: string, data: object): Channel {
118118
this.socket.send({
119119
event,
120120
data,
@@ -123,21 +123,27 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
123123
return this;
124124
}
125125

126-
here(callback: Function): ApiGatewayChannel {
126+
here(callback: Function): Channel {
127+
// TODO: implement
128+
127129
return this
128130
}
129131

130132
/**
131133
* Listen for someone joining the channel.
132134
*/
133-
joining(callback: Function): ApiGatewayChannel {
135+
joining(callback: Function): Channel {
136+
// TODO: implement
137+
134138
return this
135139
}
136140

137141
/**
138142
* Listen for someone leaving the channel.
139143
*/
140-
leaving(callback: Function): ApiGatewayChannel {
144+
leaving(callback: Function): Channel {
145+
// TODO: implement
146+
141147
return this
142148
}
143149
}

src/ApiGatewayConnector.ts renamed to src/Connector.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import {Connector} from "laravel-echo/src/connector/connector";
2-
import {ApiGatewayChannel} from "./ApiGatewayChannel";
3-
import {LaravelEchoApiGatewayWebsocket} from "./LaravelEchoApiGatewayWebsocket";
1+
import {Connector as BaseConnector} from "laravel-echo/src/connector/connector";
2+
import {Websocket} from "./Websocket";
3+
import {Channel} from "./Channel";
44

5-
export class ApiGatewayConnector extends Connector
6-
{
5+
export const broadcaster = (options: object): Connector => new Connector(options);
6+
7+
export class Connector extends BaseConnector {
78
/**
89
* The Socket.io connection instance.
910
*/
10-
socket: LaravelEchoApiGatewayWebsocket;
11+
socket: Websocket;
1112

1213
/**
1314
* All of the subscribed channel names.
1415
*/
15-
channels: { [name: string]: ApiGatewayChannel } = {};
16+
channels: { [name: string]: Channel } = {};
1617

1718
/**
1819
* Create a fresh Socket.io connection.
1920
*/
2021
connect(): void {
21-
this.socket = new LaravelEchoApiGatewayWebsocket(this.options);
22+
this.socket = new Websocket(this.options);
2223

2324
return null;
2425

@@ -35,9 +36,9 @@ export class ApiGatewayConnector extends Connector
3536
/**
3637
* Get a channel instance by name.
3738
*/
38-
channel(name: string): ApiGatewayChannel {
39+
channel(name: string): Channel {
3940
if (!this.channels[name]) {
40-
this.channels[name] = new ApiGatewayChannel(this.socket, name, this.options);
41+
this.channels[name] = new Channel(this.socket, name, this.options);
4142
}
4243

4344
return this.channels[name];
@@ -46,27 +47,27 @@ export class ApiGatewayConnector extends Connector
4647
/**
4748
* Get a private channel instance by name.
4849
*/
49-
privateChannel(name: string): ApiGatewayChannel {
50+
privateChannel(name: string): Channel {
5051
if (!this.channels['private-' + name]) {
51-
this.channels['private-' + name] = new ApiGatewayChannel(this.socket, 'private-' + name, this.options);
52+
this.channels['private-' + name] = new Channel(this.socket, 'private-' + name, this.options);
5253
}
5354

54-
return this.channels['private-' + name] as ApiGatewayChannel;
55+
return this.channels['private-' + name] as Channel;
5556
}
5657

5758
/**
5859
* Get a presence channel instance by name.
5960
*/
60-
presenceChannel(name: string): ApiGatewayChannel {
61+
presenceChannel(name: string): Channel {
6162
if (!this.channels['presence-' + name]) {
62-
this.channels['presence-' + name] = new ApiGatewayChannel(
63+
this.channels['presence-' + name] = new Channel(
6364
this.socket,
6465
'presence-' + name,
6566
this.options
6667
);
6768
}
6869

69-
return this.channels['presence-' + name] as ApiGatewayChannel;
70+
return this.channels['presence-' + name] as Channel;
7071
}
7172

7273
/**

src/LaravelEchoApiGatewayConnector.ts

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)