master 636781f7a8ce cached
11 files
29.8 KB
8.0k tokens
12 symbols
1 requests
Download .txt
Repository: lwansbrough/react-native-multipeer
Branch: master
Commit: 636781f7a8ce
Files: 11
Total size: 29.8 KB

Directory structure:
gitextract_ibkwa9_i/

├── .gitignore
├── LICENSE
├── MultipeerConnection.js
├── Peer.js
├── RCTMultipeerConnectivity.h
├── RCTMultipeerConnectivity.m
├── RCTMultipeerConnectivity.xcodeproj/
│   ├── project.pbxproj
│   └── project.xcworkspace/
│       └── contents.xcworkspacedata
├── README.md
├── index.js
└── package.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
RCTMultipeerConnectivity.xcodeproj/project.xcworkspace/xcuserdata
RCTMultipeerConnectivity.xcodeproj/xcuserdata


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2015 Loch Wansbrough

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



================================================
FILE: MultipeerConnection.js
================================================
import React, { DeviceEventEmitter, NativeModules } from 'react-native';
import { EventEmitter } from 'events';
import Peer from './Peer';
let RCTMultipeerConnectivity = NativeModules.MultipeerConnectivity;

export default class MultipeerConnection extends EventEmitter {
  
  constructor() {
    super();
    this._peers = {};
    this._connectedPeers = {};
    var peerFound = DeviceEventEmitter.addListener(
      'RCTMultipeerConnectivityPeerFound',
      ((event) => {
        var peer = new Peer(event.peer.id, event.peer.info.name);
        this._peers[peer.id] = peer;
        this.emit('peerFound', { peer });
      }).bind(this));
      
    var peerLost = DeviceEventEmitter.addListener(
      'RCTMultipeerConnectivityPeerLost',
      ((event) => {
        var peer = this._peers[event.peer.id];
        peer.emit('lost');
        this.emit('peerLost', { peer: { id: peer.id } });
        delete this._peers[event.peer.id];
        delete this._connectedPeers[event.peer.id];
      }).bind(this));
    
    var peerConnected = DeviceEventEmitter.addListener(
      'RCTMultipeerConnectivityPeerConnected',
      ((event) => {
        this._peers[event.peer.id].emit('connected');
        this._connectedPeers[event.peer.id] = this._peers[event.peer.id];
        this.emit('peerConnected', event);
      }).bind(this));
      
    var peerConnecting = DeviceEventEmitter.addListener(
      'RCTMultipeerConnectivityPeerConnecting',
      ((event) => {
        this._peers[event.peer.id].emit('connecting');
        this.emit('peerConnecting', event);
      }).bind(this));
    
    var peerDisconnected = DeviceEventEmitter.addListener(
      'RCTMultipeerConnectivityPeerDisconnected',
      ((event) => {
        this._peers[event.peer.id].emit('disconnected');
        delete this._connectedPeers[event.peer.id];
        this.emit('peerDisconnected', event);
      }).bind(this));
      
    var streamOpened = DeviceEventEmitter.addListener(
      'RCTMultipeerConnectivityStreamOpened',
      ((event) => {
        this.emit('streamOpened', event);
      }).bind(this));
    
    var invited = DeviceEventEmitter.addListener(
      'RCTMultipeerConnectivityInviteReceived',
      ((event) => {
        event.sender = this._peers[event.sender.id];
        this.emit('invite', event);
      }).bind(this));
      
    var dataReceived = DeviceEventEmitter.addListener(
      'RCTMultipeerConnectivityDataReceived',
      ((event) => {
        event.sender = this._peers[event.sender.id];
        this.emit('data', event);
      }).bind(this));
  }
  
  getAllPeers() {
    return this._peers;
  }
  
  getConnectedPeers() {
    return this._connectedPeers;
  }
  
  send(recipients, data, callback) {
    if (!callback) {
      callback = () => {};
    }
    
    var recipientIds = recipients.map((recipient) => {
      if (recipient instanceof Peer) {
        return recipient.id;
      }
      return recipient;
    });
    
    RCTMultipeerConnectivity.send(recipientIds, data, callback);
  }
  
  broadcast(data, callback) {
    if (!callback) {
      callback = () => {};
    }
    RCTMultipeerConnectivity.broadcast(data, callback);
  }
  
  invite(peerId, callback) {
    if (!callback) {
      callback = () => {};
    }
    RCTMultipeerConnectivity.invite(peerId, callback);
  }
  
  rsvp(inviteId, accept, callback) {
    if (!callback) {
      callback = () => {};
    }
    RCTMultipeerConnectivity.rsvp(inviteId, accept, callback);
  }
  
  advertise(channel, info) {
    RCTMultipeerConnectivity.advertise(channel, info);
  }
  
  browse(channel) {
    RCTMultipeerConnectivity.browse(channel);
  }
  
//  createStreamForPeer(peerId, name, callback) {
//    if (!callback) {
//      callback = () => {};
//    }
//    RCTMultipeerConnectivity.createStreamForPeer(peerId, name, callback);
//  }
}

================================================
FILE: Peer.js
================================================
import { EventEmitter } from 'events';

export default class Peer extends EventEmitter {
  constructor(id, name) {
    super();
    this.id = id;
    this.name = name;
  }
}


================================================
FILE: RCTMultipeerConnectivity.h
================================================
#import "RCTBridgeModule.h"

@import MultipeerConnectivity;

@interface RCTMultipeerConnectivity : NSObject <RCTBridgeModule, NSStreamDelegate, MCSessionDelegate, MCNearbyServiceBrowserDelegate, MCNearbyServiceAdvertiserDelegate>

@property (nonatomic, strong) NSMutableDictionary *peers;
@property (nonatomic, strong) NSMutableDictionary *connectedPeers;
@property (nonatomic, strong) NSMutableDictionary *invitationHandlers;
@property (nonatomic, strong) MCPeerID *peerID;
@property (nonatomic, strong) MCSession *session;
@property (nonatomic, strong) MCNearbyServiceBrowser *browser;
@property (nonatomic, strong) MCNearbyServiceAdvertiser *advertiser;

@end


================================================
FILE: RCTMultipeerConnectivity.m
================================================
#import "RCTMultipeerConnectivity.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
//#import "ObjectStore.h"

@implementation RCTMultipeerConnectivity

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(advertise:(NSString *)channel data:(NSDictionary *)data) {
  self.advertiser =
  [[MCNearbyServiceAdvertiser alloc] initWithPeer:self.peerID discoveryInfo:data serviceType:channel];
  self.advertiser.delegate = self;
  [self.advertiser startAdvertisingPeer];
}

RCT_EXPORT_METHOD(browse:(NSString *)channel)
{
  self.browser = [[MCNearbyServiceBrowser alloc] initWithPeer:self.peerID serviceType:channel];
  self.browser.delegate = self;
  [self.browser startBrowsingForPeers];
}

RCT_EXPORT_METHOD(invite:(NSString *)peerUUID callback:(RCTResponseSenderBlock)callback) {
  MCPeerID *peerID = [self.peers valueForKey:peerUUID];
  [self.browser invitePeer:peerID toSession:self.session withContext:nil timeout:30];
  callback(@[[NSNull null]]);
}

RCT_EXPORT_METHOD(rsvp:(NSString *)inviteID accept:(BOOL)accept callback:(RCTResponseSenderBlock)callback) {
  void (^invitationHandler)(BOOL, MCSession *) = [self.invitationHandlers valueForKey:inviteID];
  invitationHandler(accept, self.session);
  [self.invitationHandlers removeObjectForKey:inviteID];
  callback(@[[NSNull null]]);
}

RCT_EXPORT_METHOD(broadcast:(NSDictionary *)data callback:(RCTResponseSenderBlock)callback) {
  [self sendData:[self.connectedPeers allKeys] data:data callback:callback];
}

RCT_EXPORT_METHOD(send:(NSArray *)recipients data:(NSDictionary *)data callback:(RCTResponseSenderBlock)callback) {
  [self sendData:recipients data:data callback:callback];
}

RCT_EXPORT_METHOD(disconnect:(RCTResponseSenderBlock)callback) {
  [self.session disconnect];
  callback(@[[NSNull null]]);
}

// TODO: Waiting for module interop and/or streams over JS bridge

//RCT_EXPORT_METHOD(createStreamForPeer:(NSString *)peerUUID name:(NSString *)name callback:(RCTResponseSenderBlock)callback) {
//  NSError *error = nil;
//  NSString *outputStreamUUID = [[ObjectStore shared] putObject:[self.session startStreamWithName:name toPeer:[self.peers valueForKey:peerUUID] error:&error]];
//  if (error != nil) {
//    callback(@[[error description]]);
//  }
//  else {
//    callback(@[[NSNull null], outputStreamUUID]);
//  }
//}

- (instancetype)init {
  self = [super init];
  self.peers = [NSMutableDictionary dictionary];
  self.connectedPeers = [NSMutableDictionary dictionary];
  self.invitationHandlers = [NSMutableDictionary dictionary];
  self.peerID = [[MCPeerID alloc] initWithDisplayName:[[NSUUID UUID] UUIDString]];
  self.session = [[MCSession alloc] initWithPeer:self.peerID securityIdentity:nil encryptionPreference:MCEncryptionNone];
  self.session.delegate = self;
  return self;
}

- (void)sendData:(NSArray *)recipients data:(NSDictionary *)data callback:(RCTResponseSenderBlock)callback {
  NSError *error = nil;
  NSMutableArray *peers = [NSMutableArray array];
  for (NSString *peerUUID in recipients) {
    [peers addObject:[self.peers valueForKey:peerUUID]];
  }
  NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:&error];
  [self.session sendData:jsonData toPeers:peers withMode:MCSessionSendDataReliable error:&error];
  if (error == nil) {
    callback(@[[NSNull null]]);
  }
  else {
    callback(@[[error description]]);
  }
}

- (void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info {
  if ([peerID.displayName isEqualToString:self.peerID.displayName]) return;
  [self.peers setValue:peerID forKey:peerID.displayName];
  if (info == nil) {
    info = [NSDictionary dictionary];
  }
  [self.bridge.eventDispatcher sendDeviceEventWithName:@"RCTMultipeerConnectivityPeerFound"
                               body:@{
                                 @"peer": @{
                                   @"id": peerID.displayName,
                                   @"info": info
                                 }
                               }];
}

- (void)browser:(MCNearbyServiceBrowser *)browser lostPeer:(MCPeerID *)peerID {
  if ([peerID.displayName isEqualToString:self.peerID.displayName]) return;
  [self.bridge.eventDispatcher sendDeviceEventWithName:@"RCTMultipeerConnectivityPeerLost"
                               body:@{
                                 @"peer": @{
                                   @"id": peerID.displayName
                                 }
                               }];
  [self.peers removeObjectForKey:peerID.displayName];
}

- (void)advertiser:(MCNearbyServiceAdvertiser *)advertiser didReceiveInvitationFromPeer:(MCPeerID *)peerID withContext:(NSData *)context invitationHandler:(void (^)(BOOL accept, MCSession *session))invitationHandler {
  NSString *invitationUUID = [[NSUUID UUID] UUIDString];
  [self.invitationHandlers setValue:[invitationHandler copy] forKey:invitationUUID];
  [self.bridge.eventDispatcher sendDeviceEventWithName:@"RCTMultipeerConnectivityInviteReceived"
                              body:@{
                                @"invite": @{
                                  @"id": invitationUUID
                                },
                                @"peer": @{
                                  @"id": peerID.displayName
                                }
                              }];
}

- (void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state {
  if ([peerID.displayName isEqualToString:self.peerID.displayName]) return;
  if (state == MCSessionStateConnected) {
    [self.connectedPeers setValue:peerID forKey:peerID.displayName];
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"RCTMultipeerConnectivityPeerConnected"
                                 body:@{
                                   @"peer": @{
                                     @"id": peerID.displayName
                                   }
                                 }];
  }
  else if (state == MCSessionStateConnecting) {
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"RCTMultipeerConnectivityPeerConnecting"
                                 body:@{
                                   @"peer": @{
                                     @"id": peerID.displayName
                                   }
                                 }];
  }
  else if (state == MCSessionStateNotConnected) {
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"RCTMultipeerConnectivityPeerDisconnected"
                                 body:@{
                                   @"peer": @{
                                     @"id": peerID.displayName
                                   }
                                 }];
    [self.connectedPeers removeObjectForKey:peerID.displayName];

  }
}

- (void)session:(MCSession *)session didReceiveCertificate:(NSArray *)certificate fromPeer:(MCPeerID *)peerID certificateHandler:(void (^)(BOOL accept))certificateHandler {
  certificateHandler(YES);
}

// TODO: Waiting for module interop and/or streams over JS bridge

//- (void)session:(MCSession *)session didReceiveStream:(NSInputStream *)stream withName:(NSString *)streamName fromPeer:(MCPeerID *)peerID {
//  NSString *streamId = [[ObjectStore shared] putObject:stream];
//  [self.bridge.eventDispatcher sendDeviceEventWithName:@"RCTMultipeerConnectivityStreamOpened"
//                               body:@{
//                                 @"stream": @{
//                                   @"id": streamId,
//                                   @"name": streamName
//                                 },
//                                 @"peer": @{
//                                   @"id": peerID.displayName
//                                 }
//                               }];
//}

- (void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCPeerID *)peerID {
  NSError *error = nil;
  id object = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  NSDictionary *parsedJSON = [NSDictionary dictionary];
  
  if([object isKindOfClass:[NSDictionary class]]) {
    parsedJSON = object;
  }
  
  [self.bridge.eventDispatcher sendDeviceEventWithName:@"RCTMultipeerConnectivityDataReceived"
                               body:@{
                                 @"sender": @{
                                   @"id": peerID.displayName
                                 },
                                 @"data": parsedJSON
                               }];
}

// TODO: Support file transfers once we have a general spec for representing files
//
//- (void)session:(MCSession *)session didFinishReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID atURL:(NSURL *)localURL withError:(NSError *)error {
//  NSURL *destinationURL = [NSURL fileURLWithPath:@"/path/to/destination"];
//  if (![[NSFileManager defaultManager] moveItemAtURL:localURL toURL:destinationURL error:&error]) {
//    NSLog(@"[Error] %@", error);
//  }
//}
//
//- (void)session:(MCSession *)session
//didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress
//{
//  
//}


@end


================================================
FILE: RCTMultipeerConnectivity.xcodeproj/project.pbxproj
================================================
// !$*UTF8*$!
{
	archiveVersion = 1;
	classes = {
	};
	objectVersion = 46;
	objects = {

/* Begin PBXBuildFile section */
		13BE3DEE1AC21097009241FE /* RCTMultipeerConnectivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 13BE3DED1AC21097009241FE /* RCTMultipeerConnectivity.m */; };
		41EEABC21B239B08005BCB34 /* MultipeerConnectivity.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 41EEABC11B239B08005BCB34 /* MultipeerConnectivity.framework */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
		58B511D91A9E6C8500147676 /* CopyFiles */ = {
			isa = PBXCopyFilesBuildPhase;
			buildActionMask = 2147483647;
			dstPath = "include/$(PRODUCT_NAME)";
			dstSubfolderSpec = 16;
			files = (
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
		134814201AA4EA6300B7C361 /* libRCTMultipeerConnectivity.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTMultipeerConnectivity.a; sourceTree = BUILT_PRODUCTS_DIR; };
		13BE3DEC1AC21097009241FE /* RCTMultipeerConnectivity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTMultipeerConnectivity.h; sourceTree = "<group>"; };
		13BE3DED1AC21097009241FE /* RCTMultipeerConnectivity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMultipeerConnectivity.m; sourceTree = "<group>"; };
		41EEABC11B239B08005BCB34 /* MultipeerConnectivity.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MultipeerConnectivity.framework; path = System/Library/Frameworks/MultipeerConnectivity.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
		58B511D81A9E6C8500147676 /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
				41EEABC21B239B08005BCB34 /* MultipeerConnectivity.framework in Frameworks */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
		134814211AA4EA7D00B7C361 /* Products */ = {
			isa = PBXGroup;
			children = (
				134814201AA4EA6300B7C361 /* libRCTMultipeerConnectivity.a */,
			);
			name = Products;
			sourceTree = "<group>";
		};
		58B511D21A9E6C8500147676 = {
			isa = PBXGroup;
			children = (
				41EEABC11B239B08005BCB34 /* MultipeerConnectivity.framework */,
				13BE3DEC1AC21097009241FE /* RCTMultipeerConnectivity.h */,
				13BE3DED1AC21097009241FE /* RCTMultipeerConnectivity.m */,
				134814211AA4EA7D00B7C361 /* Products */,
			);
			sourceTree = "<group>";
		};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
		58B511DA1A9E6C8500147676 /* RCTMultipeerConnectivity */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTMultipeerConnectivity" */;
			buildPhases = (
				58B511D71A9E6C8500147676 /* Sources */,
				58B511D81A9E6C8500147676 /* Frameworks */,
				58B511D91A9E6C8500147676 /* CopyFiles */,
			);
			buildRules = (
			);
			dependencies = (
			);
			name = RCTMultipeerConnectivity;
			productName = RCTDataManager;
			productReference = 134814201AA4EA6300B7C361 /* libRCTMultipeerConnectivity.a */;
			productType = "com.apple.product-type.library.static";
		};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
		58B511D31A9E6C8500147676 /* Project object */ = {
			isa = PBXProject;
			attributes = {
				LastUpgradeCheck = 0610;
				ORGANIZATIONNAME = Facebook;
				TargetAttributes = {
					58B511DA1A9E6C8500147676 = {
						CreatedOnToolsVersion = 6.1.1;
					};
				};
			};
			buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTMultipeerConnectivity" */;
			compatibilityVersion = "Xcode 3.2";
			developmentRegion = English;
			hasScannedForEncodings = 0;
			knownRegions = (
				en,
			);
			mainGroup = 58B511D21A9E6C8500147676;
			productRefGroup = 58B511D21A9E6C8500147676;
			projectDirPath = "";
			projectRoot = "";
			targets = (
				58B511DA1A9E6C8500147676 /* RCTMultipeerConnectivity */,
			);
		};
/* End PBXProject section */

/* Begin PBXSourcesBuildPhase section */
		58B511D71A9E6C8500147676 /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				13BE3DEE1AC21097009241FE /* RCTMultipeerConnectivity.m in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
		58B511ED1A9E6C8500147676 /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_SEARCH_USER_PATHS = NO;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				COPY_PHASE_STRIP = NO;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_OPTIMIZATION_LEVEL = 0;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"DEBUG=1",
					"$(inherited)",
				);
				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				IPHONEOS_DEPLOYMENT_TARGET = 7.0;
				MTL_ENABLE_DEBUG_INFO = YES;
				ONLY_ACTIVE_ARCH = YES;
				SDKROOT = iphoneos;
			};
			name = Debug;
		};
		58B511EE1A9E6C8500147676 /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_SEARCH_USER_PATHS = NO;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				COPY_PHASE_STRIP = YES;
				ENABLE_NS_ASSERTIONS = NO;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				IPHONEOS_DEPLOYMENT_TARGET = 7.0;
				MTL_ENABLE_DEBUG_INFO = NO;
				SDKROOT = iphoneos;
				VALIDATE_PRODUCT = YES;
			};
			name = Release;
		};
		58B511F01A9E6C8500147676 /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				HEADER_SEARCH_PATHS = (
					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
					"$(SRCROOT)/../../React/**",
					"$(SRCROOT)/../react-native/React/**",
				);
				LIBRARY_SEARCH_PATHS = "$(inherited)";
				OTHER_LDFLAGS = "-ObjC";
				PRODUCT_NAME = RCTMultipeerConnectivity;
				SKIP_INSTALL = YES;
			};
			name = Debug;
		};
		58B511F11A9E6C8500147676 /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				HEADER_SEARCH_PATHS = (
					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
					"$(SRCROOT)/../../React/**",
					"$(SRCROOT)/../react-native/React/**",
				);
				LIBRARY_SEARCH_PATHS = "$(inherited)";
				OTHER_LDFLAGS = "-ObjC";
				PRODUCT_NAME = RCTMultipeerConnectivity;
				SKIP_INSTALL = YES;
			};
			name = Release;
		};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
		58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTMultipeerConnectivity" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				58B511ED1A9E6C8500147676 /* Debug */,
				58B511EE1A9E6C8500147676 /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Release;
		};
		58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTMultipeerConnectivity" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				58B511F01A9E6C8500147676 /* Debug */,
				58B511F11A9E6C8500147676 /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Release;
		};
/* End XCConfigurationList section */
	};
	rootObject = 58B511D31A9E6C8500147676 /* Project object */;
}


================================================
FILE: RCTMultipeerConnectivity.xcodeproj/project.xcworkspace/contents.xcworkspacedata
================================================
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
   version = "1.0">
   <FileRef
      location = "self:">
   </FileRef>
</Workspace>


================================================
FILE: README.md
================================================
# react-native-multipeer

Communicate over ad hoc wifi using Multipeer Connectivity.

## Known Issues
Below is a list of known issues. Pull requests are welcome for any of these issues!

- No support for streams in React Native, so streaming is currently unavailable.
- No support for resource transfers: I want this to work seamlessly with other file resources for other uses, so I'm waiting for those specs to be finalized.

## Getting started

1. `npm install react-native-multipeer@latest --save`
2. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
3. Go to `node_modules` ➜ `react-native-multipeer` and add `RCTMultipeerConnectivity.xcodeproj`
4. In XCode, in the project navigator, select your project. Add `libRCTMultipeerConnectivity.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
5. Click `RCTMultipeerConnectivity.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../react-native/React` and `$(SRCROOT)/../../React` - mark both as `recursive`.
5. Run your project (`Cmd+R`)

## Usage

All you need is to `require` the `react-native-multipeer` module and then you can start using the singleton instance.

```javascript
var React = require('react-native');
var {
  AppRegistry,
  ListView,
  StyleSheet,
  Text,
  View,
  TouchableHighlight
} = React;
var MultipeerConnectivity = require('react-native-multipeer');

function getStateFromSources() {
  var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    return {
      dataSource: ds.cloneWithRows(MultipeerConnectivity.getAllPeers())
    };
}

var peerApp = React.createClass({
  getInitialState: function() {
    return getStateFromSources()
  },
  componentDidMount() {
    MultipeerConnectivity.on('peerFound', this._onChange);
    MultipeerConnectivity.on('peerLost', this._onChange);
    MultipeerConnectivity.on('invite', ((event) => {
      // Automatically accept invitations
      MultipeerConnectivity.rsvp(event.invite.id, true);
    }).bind(this));
    MultipeerConnectivity.on('peerConnected', (event) => {
      alert(event.peer.id + ' connected!');
    });
    MultipeerConnectivity.advertise('channel1', { name: 'User-' + Math.round(1e6 * Math.random()) });
    MultipeerConnectivity.browse('channel1');
  },

  renderRow(peer) {
    return (
      <TouchableHighlight onPress={this.invite.bind(this, peer)} style={styles.row}>
        <View>
          <Text>{peer.name}</Text>
        </View>
      </TouchableHighlight>
    );
  },
  
  render: function() {
    return (
      <View style={styles.container}>
        <ListView
          style={styles.peers}
          dataSource={this.state.dataSource}
          renderRow={this.renderRow}
        />
      </View>
    );
  },
  
  _invite(peer) {
    MultipeerConnectivity.invite(peer.id);
  },
  
  _onChange() {
    this.setState(getStateFromSources());
  }
});


var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'transparent',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
  },
});

AppRegistry.registerComponent('peerApp', () => peerApp);
```

## `MultipeerConnectivity` methods

### Channels

#### `advertise(channelId, info)`

Allow discovery of yourself as a peer in a given channel. `channelId` can be any string. `info` is an object containing data which will be passed to other peers when you join the channel.

#### `browse(channelId)`

Browse for peers on a given channel.

#### `getAllPeers()`

Gets all the peers in the current channel.


### Sessions

#### `getConnectedPeers()`

Gets all the peers in the current session.


#### `disconnect([callback])`

Disconnect from the current session.


#### `invite(peerId [, callback])`

Invite a peer from your channel into your session.


#### `rsvp(inviteId, accept [, callback])`

Accept/decline a session invitation.


### Communication

#### `broadcast(data [, callback<err>])`

Send data to all connected peers in the current channel.


#### `send(data, recipients [, callback<err>])`

Send data to specific peers in the current channel. `recipients` is an array of peer IDs or `Peer`s.

### `MultipeerConnectivity` Events

`MultipeerConnectivity` inherits from `EventEmitter` - as such the `.on` method is available for listening to important events. Below is a list of those events.

#### `data`

Event properties: `Peer sender`, `data`

Fired when new data is received from `sender`.

#### `peerFound`

Event properties: `peer`

A new peer was found in the current channel.


#### `peerLost`

Event properties: `peer`

A peer left the current channel.

#### `peerConnected`

Event properties: `peer`

A peer has connected to your session.

#### `peerConnecting`

Event properties: `peer`

A peer is connecting to your session.

#### `peerDisconnected`

Event properties: `peer`

A peer disconnected from your session.

#### `invite`

Event properties: `sender`, `invite`

You have been invited to a session.


## `Peer` methods

### Events

#### `connected`

The peer connected to the current session.


#### `connecting`

The peer is connecting to the current session.


#### `disconnected`

The peer disconnected from the current session.

#### `lost`

The peer left the current channel.


## Todo
These are some features I think would be important/beneficial to have included with this module. Pull requests welcome!

- [ ] Stream support
- [ ] Resource transfers


================================================
FILE: index.js
================================================
import MultipeerConnection from './MultipeerConnection';
module.exports = new MultipeerConnection();

================================================
FILE: package.json
================================================
{
  "name": "react-native-multipeer",
  "version": "0.1.1",
  "repository": {
    "type" : "git",
    "url" : "https://github.com/lwansbrough/react-native-multipeer.git"
  },
  "author": "Lochlan Wansbrough <lochie@live.com> (http://lwansbrough.com)",
  "description": "Communicate over ad hoc wifi using Multipeer Connectivity",
  "dependencies": {
    "events": "^1.0.2"
  },
  "main": "index.js",
  "keywords": [
    "react-native",
    "react",
    "native",
    "multipeer",
    "connectivity",
    "adhoc",
    "wifi",
    "p2p"
  ]
}
Download .txt
gitextract_ibkwa9_i/

├── .gitignore
├── LICENSE
├── MultipeerConnection.js
├── Peer.js
├── RCTMultipeerConnectivity.h
├── RCTMultipeerConnectivity.m
├── RCTMultipeerConnectivity.xcodeproj/
│   ├── project.pbxproj
│   └── project.xcworkspace/
│       └── contents.xcworkspacedata
├── README.md
├── index.js
└── package.json
Download .txt
SYMBOL INDEX (12 symbols across 2 files)

FILE: MultipeerConnection.js
  class MultipeerConnection (line 6) | class MultipeerConnection extends EventEmitter {
    method constructor (line 8) | constructor() {
    method getAllPeers (line 74) | getAllPeers() {
    method getConnectedPeers (line 78) | getConnectedPeers() {
    method send (line 82) | send(recipients, data, callback) {
    method broadcast (line 97) | broadcast(data, callback) {
    method invite (line 104) | invite(peerId, callback) {
    method rsvp (line 111) | rsvp(inviteId, accept, callback) {
    method advertise (line 118) | advertise(channel, info) {
    method browse (line 122) | browse(channel) {

FILE: Peer.js
  class Peer (line 3) | class Peer extends EventEmitter {
    method constructor (line 4) | constructor(id, name) {
Condensed preview — 11 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (33K chars).
[
  {
    "path": ".gitignore",
    "chars": 112,
    "preview": "RCTMultipeerConnectivity.xcodeproj/project.xcworkspace/xcuserdata\nRCTMultipeerConnectivity.xcodeproj/xcuserdata\n"
  },
  {
    "path": "LICENSE",
    "chars": 1083,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2015 Loch Wansbrough\n\nPermission is hereby granted, free of charge, to any person o"
  },
  {
    "path": "MultipeerConnection.js",
    "chars": 3824,
    "preview": "import React, { DeviceEventEmitter, NativeModules } from 'react-native';\nimport { EventEmitter } from 'events';\nimport P"
  },
  {
    "path": "Peer.js",
    "chars": 174,
    "preview": "import { EventEmitter } from 'events';\n\nexport default class Peer extends EventEmitter {\n  constructor(id, name) {\n    s"
  },
  {
    "path": "RCTMultipeerConnectivity.h",
    "chars": 663,
    "preview": "#import \"RCTBridgeModule.h\"\n\n@import MultipeerConnectivity;\n\n@interface RCTMultipeerConnectivity : NSObject <RCTBridgeMo"
  },
  {
    "path": "RCTMultipeerConnectivity.m",
    "chars": 9216,
    "preview": "#import \"RCTMultipeerConnectivity.h\"\n#import \"RCTBridge.h\"\n#import \"RCTEventDispatcher.h\"\n//#import \"ObjectStore.h\"\n\n@im"
  },
  {
    "path": "RCTMultipeerConnectivity.xcodeproj/project.pbxproj",
    "chars": 8966,
    "preview": "// !$*UTF8*$!\n{\n\tarchiveVersion = 1;\n\tclasses = {\n\t};\n\tobjectVersion = 46;\n\tobjects = {\n\n/* Begin PBXBuildFile section *"
  },
  {
    "path": "RCTMultipeerConnectivity.xcodeproj/project.xcworkspace/contents.xcworkspacedata",
    "chars": 135,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Workspace\n   version = \"1.0\">\n   <FileRef\n      location = \"self:\">\n   </FileRef"
  },
  {
    "path": "README.md",
    "chars": 5693,
    "preview": "# react-native-multipeer\n\nCommunicate over ad hoc wifi using Multipeer Connectivity.\n\n## Known Issues\nBelow is a list of"
  },
  {
    "path": "index.js",
    "chars": 100,
    "preview": "import MultipeerConnection from './MultipeerConnection';\nmodule.exports = new MultipeerConnection();"
  },
  {
    "path": "package.json",
    "chars": 541,
    "preview": "{\n  \"name\": \"react-native-multipeer\",\n  \"version\": \"0.1.1\",\n  \"repository\": {\n    \"type\" : \"git\",\n    \"url\" : \"https://g"
  }
]

About this extraction

This page contains the full source code of the lwansbrough/react-native-multipeer GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 11 files (29.8 KB), approximately 8.0k tokens, and a symbol index with 12 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!