Skip to content

Commit

Permalink
Add iceServers and iceTransportPolicy to client
Browse files Browse the repository at this point in the history
  • Loading branch information
yandeu committed May 9, 2019
1 parent 5c1fed0 commit 050c485
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bundles/latest/geckos.io-client.latest.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bundles/versions/geckos.io-client.1.1.1.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions cheatsheet.md
Expand Up @@ -8,9 +8,11 @@ import geckos from '@geckos.io/client'

/**
* start geckos client with these options
* @param {string} options.url default is `${location.protocol}//${location.hostname}`
* @param {number} options.port default is 9208
* @param {string} label Default: 'geckos.io'.
* @param options.url default is `${location.protocol}//${location.hostname}`
* @param options.port default is 9208
* @param options.label Default: 'geckos.io'.
* @param options.iceServers Default: [].
* @param options.iceTransportPolicy Default: 'all'.
*/
const channel = geckos(options)

Expand Down Expand Up @@ -38,6 +40,7 @@ import geckos from '@geckos.io/server'
/**
* start geckos server with these options
* @param options.iceServers Default: [].
* @param options.iceTransportPolicy Default: 'all'.
* @param options.label Default: 'geckos.io'.
* @param options.ordered Default: false.
* @param options.maxPacketLifeTime Default: null.
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
@@ -1,6 +1,6 @@
{
"name": "@geckos.io/client",
"version": "1.1.0",
"version": "1.1.1",
"description": "Real-time client/server communication over UDP using WebRTC and Node.js",
"main": "lib/index.js",
"author": "Yannick Deubel (https://github.com/yandeu)",
Expand Down
21 changes: 15 additions & 6 deletions packages/client/src/client.ts
Expand Up @@ -8,17 +8,18 @@ import {
EventName,
EventCallbackClient,
ConnectionEventCallbackClient,
EventCallbackRawMessage
EventCallbackRawMessage,
ClientOptions
} from '@geckos.io/common/lib/typings'

export class ClientChannel {
private peerConnection: PeerConnection
private connectionsManager: ConnectionsManagerClient
private url: string

constructor(url: string, port: number, label: string) {
constructor(url: string, port: number, label: string, rtcConfiguration: RTCConfiguration) {
this.url = `${url}:${port}`
this.connectionsManager = new ConnectionsManagerClient(this.url, label)
this.connectionsManager = new ConnectionsManagerClient(this.url, label, rtcConfiguration)
}

private onconnectionstatechange() {
Expand Down Expand Up @@ -104,10 +105,18 @@ export class ClientChannel {
* @param options.url The url of the server. Default: \`${location.protocol}//${location.hostname}\`.
* @param options.port The port of the server. Default: 9208.
* @param options.label The label of the DataChannel. Default: 'geckos.io'.
* @param options.iceServers An array of RTCIceServers. See https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer.
* @param options.iceTransportPolicy RTCIceTransportPolicy enum defines string constants which can be used to limit the transport policies of the ICE candidates to be considered during the connection process.
*/
const geckosClient = (options: { url?: string; port?: number; label?: string } = {}) => {
const { url = `${location.protocol}//${location.hostname}`, port = 9208, label = 'geckos.io' } = options
return new ClientChannel(url, port, label)
const geckosClient = (options: ClientOptions = {}) => {
const {
iceServers = [],
iceTransportPolicy = 'all',
url = `${location.protocol}//${location.hostname}`,
port = 9208,
label = 'geckos.io'
} = options
return new ClientChannel(url, port, label, { iceServers, iceTransportPolicy })
}

export default geckosClient
8 changes: 6 additions & 2 deletions packages/client/src/wrtc/connectionsManager.ts
Expand Up @@ -19,7 +19,7 @@ export default class ConnectionsManagerClient {
SendMessage(this.dataChannel, eventName, data)
}

constructor(public url: string, public label: string) {}
constructor(public url: string, public label: string, public rtcConfiguration: RTCConfiguration) {}

onDataChannel = (ev: RTCDataChannelEvent) => {
const { channel } = ev
Expand Down Expand Up @@ -54,7 +54,11 @@ export default class ConnectionsManagerClient {

const { id, localDescription } = this.remotePeerConnection

const configuration: RTCConfiguration = {}
const configuration: RTCConfiguration = {
// @ts-ignore
sdpSemantics: 'unified-plan',
...this.rtcConfiguration
}

const RTCPc =
RTCPeerConnection ||
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
@@ -1,6 +1,6 @@
{
"name": "@geckos.io/common",
"version": "1.0.1",
"version": "1.0.2",
"description": "The common module for @geckos.io/server and @geckos.io/client.",
"main": "lib",
"author": "Yannick Deubel (https://github.com/yandeu)",
Expand Down
8 changes: 8 additions & 0 deletions packages/common/src/typings.ts
Expand Up @@ -18,6 +18,14 @@ export interface ServerOptions {
maxPacketLifeTime?: number
}

export interface ClientOptions {
iceServers?: RTCIceServer[]
iceTransportPolicy?: RTCIceTransportPolicy
url?: string
port?: number
label?: string
}

export interface EventCallbackClient {
(data: Data): void
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
@@ -1,6 +1,6 @@
{
"name": "@geckos.io/server",
"version": "1.1.1",
"version": "1.1.2",
"description": "Real-time client/server communication over UDP using WebRTC and Node.js",
"main": "lib/index.js",
"author": "Yannick Deubel (https://github.com/yandeu)",
Expand Down

0 comments on commit 050c485

Please sign in to comment.