-
Notifications
You must be signed in to change notification settings - Fork 79
Feature - Add option to select transport type #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
HNeukermans
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome PR. @Saaka.
Valueable feature you have added there.
I've carefully reviewed you code.
If you can fix the remarks I've made I will be very happy to merge it in :-)
src/services/signalr.ts
Outdated
| try { | ||
| let serialized = JSON.stringify(configuration.qs); | ||
| let serializedQs = JSON.stringify(configuration.qs); | ||
| let serializedTransport = JSON.stringify(configuration.transport); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to serialize since it is just a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is serialized, because it is string or array of strings.
| console.log(`configuration:[hubName: '${configuration.hubName}'] ...`); | ||
| console.log(`configuration:[qs: '${serialized}'] ...`); | ||
| console.log(`configuration:[qs: '${serializedQs}'] ...`); | ||
| console.log(`configuration:[transport: '${serializedTransport}'] ...`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can change this to console.log(configuration:[transport: '${configuration.transport}'] ...); ?
| public withCredentials: boolean; | ||
|
|
||
| /**Allows you to specify transport. You can specify a fallback order if you wan't to try specific transports in order. */ | ||
| public transport?: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this of type string? array of strings? Can you explain the possible values you are expecting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is either a string or array of strings. I can change it to array of TransportConnection objects, and change it to string or array of strings before passing it to connect function. This way user wont be able to pass invalid parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Saaka
great idea. great minds think alike :-)
make it ConnectionTransport[] then , agree?
| @@ -0,0 +1,6 @@ | |||
| export class ConnectionTransport { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you design your ConnectionTransport as a 'value' object. You can use ConnectionStatus/ConnectionStatuses as a example. I use this design because signalr connection status is basically a string that has only limited range of values. This design prevents the api user from filling in something random
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also make sure to test your ConnectionTransports & Connectiontransport object. You can use
connection.statuses.spec.ts & connection.status.spec.ts as an example.
| expect(configuration.hubName).toBe(null); | ||
| expect(configuration.qs).toBe(null); | ||
| expect(configuration.url).toBe(null); | ||
| expect(configuration.transport).toBe(null, 'transport should be null'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then make this an empty array instead of null
| /** Allows withCredentials */ | ||
| withCredentials?: boolean; | ||
|
|
||
| /**Allows you to specify transport. You can specify a fallback order if you wan't to try specific transports in order. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to keep linter happy please a space:
instead of /**XXXX do /** XXX
HNeukermans
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice works @Saaka,
Keep in mind to create these files:
TransportConnection.ts equivalent to ConnectionStatus
TransportConnections.ts equivalent to ConnectionStatuses
TransportConnection.spec.ts equivalent to ConnectionStatus.spec.ts
TransportConnections.spec.ts equivalent to ConnectionStatuses.spec.ts
Let me know if thing are unclear.
| this.url = null; | ||
| this.jsonp = false; | ||
| this.withCredentials = false; | ||
| this.transport = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.transport = [];
README.md
Outdated
| config.qs = { user: 'donald' }; | ||
| config.url = 'http://ng2-signalr-backend.azurewebsites.net/'; | ||
| // Specify one Transport: config.transport = ConnectionTransport.LONG_POLLING; or fallback options with order like below. | ||
| config.transport = [ConnectionTransport.WEB_SOCKETS, ConnectionTransport.LONG_POLLING]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you makes this config.transport = [ConnectionTransports.webSockets, ConnectionTransports.longPolling]
src/services/signalr.ts
Outdated
| return $promise; | ||
| } | ||
|
|
||
| private getConnectionStartParams(withCredentials: boolean, jsonp: boolean, transport: any) : any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let jTransports = convertTransports(configuration.transports);
jConnection.start({ withCredentials: configuration.withCredentials, jsonp: configuration.jsonp, transport: jTransports })
convertTransports(Transports ) {
return transports.map((t) => t.name); ...
}
|
I have made transport as follows: |
|
allright @Saaka, |
Add option to select transport type: specify one transport or ordered fallback list.