Skip to content
Permalink
Browse files

Add iceServers and iceTransportPolicy to client

  • Loading branch information...
yandeu committed May 9, 2019
1 parent 5c1fed0 commit 050c485ca01055e73fa08119ada892c19721186b

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more.

@@ -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)
@@ -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.
@@ -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)",
@@ -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() {
@@ -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
@@ -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
@@ -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 ||
@@ -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)",
@@ -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
}
@@ -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)",

0 comments on commit 050c485

Please sign in to comment.
You can’t perform that action at this time.