1 /** 2 A WebSocket client implementation 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.websocketclient; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.websocketmultiplayerpeer; 24 /** 25 A WebSocket client implementation 26 27 This class implements a WebSocket client compatible with any RFC 6455 complaint WebSocket server. 28 This client can be optionally used as a network peer for the $(D MultiplayerAPI). 29 After starting the client ($(D connectToUrl)), you will need to $(D NetworkedMultiplayerPeer.poll) it at regular intervals (e.g. inside $(D Node._process)). 30 You will received appropriate signals when connecting, disconnecting, or when new data is available. 31 */ 32 @GodotBaseClass struct WebSocketClient 33 { 34 enum string _GODOT_internal_name = "WebSocketClient"; 35 public: 36 @nogc nothrow: 37 union { godot_object _godot_object; WebSocketMultiplayerPeer _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct _classBinding 42 { 43 __gshared: 44 @GodotName("connect_to_url") GodotMethod!(GodotError, String, PoolStringArray, bool) connectToUrl; 45 @GodotName("disconnect_from_host") GodotMethod!(void, long, String) disconnectFromHost; 46 @GodotName("set_verify_ssl_enabled") GodotMethod!(void, bool) setVerifySslEnabled; 47 @GodotName("is_verify_ssl_enabled") GodotMethod!(bool) isVerifySslEnabled; 48 } 49 bool opEquals(in WebSocketClient other) const { return _godot_object.ptr is other._godot_object.ptr; } 50 WebSocketClient opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 51 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 52 mixin baseCasts; 53 static WebSocketClient _new() 54 { 55 static godot_class_constructor constructor; 56 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("WebSocketClient"); 57 if(constructor is null) return typeof(this).init; 58 return cast(WebSocketClient)(constructor()); 59 } 60 @disable new(size_t s); 61 /** 62 Connect to the given URL requesting one of the given `protocols` as sub-protocol. 63 If `true` is passed as `gd_mp_api`, the client will behave like a network peer for the $(D MultiplayerAPI). Note: connections to non Godot servers will not work, and $(D dataReceived) will not be emitted when this option is true. 64 */ 65 GodotError connectToUrl(StringArg0)(in StringArg0 url, in PoolStringArray protocols = PoolStringArray.init, in bool gd_mp_api = false) 66 { 67 checkClassBinding!(typeof(this))(); 68 return ptrcall!(GodotError)(_classBinding.connectToUrl, _godot_object, url, protocols, gd_mp_api); 69 } 70 /** 71 Disconnect this client from the connected host. See $(D WebSocketPeer.close) for more info. 72 */ 73 void disconnectFromHost(StringArg1)(in long code = 1000, in StringArg1 reason = "") 74 { 75 checkClassBinding!(typeof(this))(); 76 ptrcall!(void)(_classBinding.disconnectFromHost, _godot_object, code, reason); 77 } 78 /** 79 80 */ 81 void setVerifySslEnabled(in bool enabled) 82 { 83 checkClassBinding!(typeof(this))(); 84 ptrcall!(void)(_classBinding.setVerifySslEnabled, _godot_object, enabled); 85 } 86 /** 87 88 */ 89 bool isVerifySslEnabled() const 90 { 91 checkClassBinding!(typeof(this))(); 92 return ptrcall!(bool)(_classBinding.isVerifySslEnabled, _godot_object); 93 } 94 /** 95 Enable or disable SSL certificate verification. Note: You must specify the certificates to be used in the project settings for it to work when exported. 96 */ 97 @property bool verifySsl() 98 { 99 return isVerifySslEnabled(); 100 } 101 /// ditto 102 @property void verifySsl(bool v) 103 { 104 setVerifySslEnabled(v); 105 } 106 }