Feature - Add option to select transport type #53
Conversation
Awesome PR. @Saaka. |
@@ -25,13 +25,15 @@ export class SignalR { | |||
let configuration = this.merge(options ? options : {}); | |||
|
|||
try { | |||
let serialized = JSON.stringify(configuration.qs); | |||
let serializedQs = JSON.stringify(configuration.qs); | |||
let serializedTransport = JSON.stringify(configuration.transport); |
HNeukermans
May 17, 2017
Owner
no need to serialize since it is just a string
no need to serialize since it is just a string
Saaka
May 17, 2017
Author
Contributor
It is serialized, because it is string or array of strings.
It is serialized, because it is string or array of strings.
|
||
if (configuration.logging) { | ||
console.log(`Connecting with...`); | ||
console.log(`configuration:[url: '${configuration.url}'] ...`); | ||
console.log(`configuration:[hubName: '${configuration.hubName}'] ...`); | ||
console.log(`configuration:[qs: '${serialized}'] ...`); | ||
console.log(`configuration:[qs: '${serializedQs}'] ...`); | ||
console.log(`configuration:[transport: '${serializedTransport}'] ...`); |
HNeukermans
May 17, 2017
Owner
you can change this to console.log(configuration:[transport: '${configuration.transport}'] ...
); ?
you can change this to console.log(configuration:[transport: '${configuration.transport}'] ...
); ?
@@ -19,13 +19,17 @@ export class SignalRConfiguration { | |||
/** Allows withCredentials. This flag can be used to suppport CORS */ | |||
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; |
HNeukermans
May 17, 2017
Owner
Is this of type string? array of strings? Can you explain the possible values you are expecting
Is this of type string? array of strings? Can you explain the possible values you are expecting
Saaka
May 17, 2017
Author
Contributor
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.
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.
@@ -0,0 +1,6 @@ | |||
export class ConnectionTransport { |
HNeukermans
May 17, 2017
Owner
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
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
HNeukermans
May 17, 2017
Owner
Also make sure to test your ConnectionTransports & Connectiontransport object. You can use
connection.statuses.spec.ts & connection.status.spec.ts as an example.
Also make sure to test your ConnectionTransports & Connectiontransport object. You can use
connection.statuses.spec.ts & connection.status.spec.ts as an example.
@@ -8,6 +8,7 @@ describe('SignalRConfiguration', () => { | |||
expect(configuration.hubName).toBe(null); | |||
expect(configuration.qs).toBe(null); | |||
expect(configuration.url).toBe(null); | |||
expect(configuration.transport).toBe(null, 'transport should be null'); |
HNeukermans
May 17, 2017
Owner
nice
nice
HNeukermans
May 17, 2017
Owner
then make this an empty array instead of null
then make this an empty array instead of null
@@ -14,4 +14,7 @@ export interface IConnectionOptions { | |||
|
|||
/** 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. */ |
HNeukermans
May 17, 2017
Owner
to keep linter happy please a space:
instead of /**XXXX do /** XXX
to keep linter happy please a space:
instead of /**XXXX do /** XXX
Nice works @Saaka, Keep in mind to create these files: Let me know if thing are unclear. |
constructor() { | ||
this.hubName = null; | ||
this.logging = false; | ||
this.qs = null; | ||
this.url = null; | ||
this.jsonp = false; | ||
this.withCredentials = false; | ||
this.transport = null; |
HNeukermans
May 17, 2017
Owner
this.transport = [];
this.transport = [];
// <= v1.0.9 | ||
const config = new SignalRConfiguration(); | ||
config.hubName = 'Ng2SignalRHub'; //default | ||
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]; |
HNeukermans
May 17, 2017
Owner
can you makes this config.transport = [ConnectionTransports.webSockets, ConnectionTransports.longPolling]
can you makes this config.transport = [ConnectionTransports.webSockets, ConnectionTransports.longPolling]
@@ -65,6 +65,17 @@ export class SignalR { | |||
|
|||
return $promise; | |||
} | |||
|
|||
private getConnectionStartParams(withCredentials: boolean, jsonp: boolean, transport: any) : any { |
HNeukermans
May 17, 2017
Owner
let jTransports = convertTransports(configuration.transports);
jConnection.start({ withCredentials: configuration.withCredentials, jsonp: configuration.jsonp, transport: jTransports })
convertTransports(Transports ) {
return transports.map((t) => t.name); ...
}
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, |
4c30691
into
HNeukermans:master
Add option to select transport type: specify one transport or ordered fallback list.