11/// <reference path='../../../third_party/typings/browser.d.ts' />
22
33import datachannel = require( './datachannel' ) ;
4- import djb2 = require( '../crypto/djb2hash' ) ;
54import handler = require( '../handler/queue' ) ;
65import logging = require( '../logging/logging' ) ;
76import signals = require( './signals' ) ;
@@ -23,6 +22,16 @@ export enum State {
2322 CLOSED // End-state, cannot change.
2423}
2524
25+ // Quick port of djb2 to TypeScript:
26+ // http://www.cse.yorku.ca/~oz/hash.html
27+ function djb2 ( s : string ) : number {
28+ let hash = 5381 ;
29+ for ( let i = 0 ; i < s . length ; i ++ ) {
30+ hash = ( ( hash << 5 ) + hash ) + s . charCodeAt ( i ) ; // hash * 33 + c
31+ }
32+ return hash ;
33+ }
34+
2635export interface PeerConnection < TSignallingMessage > {
2736 // Fulfills once a connection been established with the peer.
2837 // Rejects if there is an error establishing the connection.
@@ -353,8 +362,8 @@ export class PeerConnectionClass implements PeerConnection<signals.Message> {
353362 if ( state === 'have-local-offer' ) {
354363 return this . pc_ . getLocalDescription ( ) . then (
355364 ( localOffer :freedom . RTCPeerConnection . RTCSessionDescription ) => {
356- if ( djb2 . stringHash ( JSON . stringify ( remoteOffer . sdp ) ) <
357- djb2 . stringHash ( JSON . stringify ( localOffer . sdp ) ) ) {
365+ if ( djb2 ( JSON . stringify ( remoteOffer . sdp ) ) <
366+ djb2 ( JSON . stringify ( localOffer . sdp ) ) ) {
358367 // TODO: implement reset and use their offer.
359368 return Promise . reject ( 'Simultaneous offers not yet implemented.' ) ;
360369 } else {
0 commit comments