blob: 06c65201b8593789d931dc391c517983f9b78206 [file] [log] [blame]
tkchin@webrtc.org87776a82014-12-09 19:32:35 +00001/*
2 * libjingle
3 * Copyright 2014, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#import <Foundation/Foundation.h>
29
30#import "ARDSignalingMessage.h"
31
32typedef NS_ENUM(NSInteger, ARDWebSocketChannelState) {
33 // State when disconnected.
34 kARDWebSocketChannelStateClosed,
35 // State when connection is established but not ready for use.
36 kARDWebSocketChannelStateOpen,
37 // State when connection is established and registered.
38 kARDWebSocketChannelStateRegistered,
39 // State when connection encounters a fatal error.
40 kARDWebSocketChannelStateError
41};
42
43@class ARDWebSocketChannel;
44@protocol ARDWebSocketChannelDelegate <NSObject>
45
46- (void)channel:(ARDWebSocketChannel *)channel
47 didChangeState:(ARDWebSocketChannelState)state;
48
49- (void)channel:(ARDWebSocketChannel *)channel
50 didReceiveMessage:(ARDSignalingMessage *)message;
51
52@end
53
54// Wraps a WebSocket connection to the AppRTC WebSocket server.
55@interface ARDWebSocketChannel : NSObject
56
57@property(nonatomic, readonly) NSString *roomId;
58@property(nonatomic, readonly) NSString *clientId;
59@property(nonatomic, readonly) ARDWebSocketChannelState state;
60@property(nonatomic, weak) id<ARDWebSocketChannelDelegate> delegate;
61
62- (instancetype)initWithURL:(NSURL *)url
63 restURL:(NSURL *)restURL
64 delegate:(id<ARDWebSocketChannelDelegate>)delegate;
65
66// Registers with the WebSocket server for the given room and client id once
67// the web socket connection is open.
68- (void)registerForRoomId:(NSString *)roomId
69 clientId:(NSString *)clientId;
70
71// Sends data over the WebSocket connection if registered, otherwise POSTs to
72// the web socket server instead.
73- (void)sendData:(NSData *)data;
74
75@end